34 lines
639 B
Go
34 lines
639 B
Go
|
package component
|
||
|
|
||
|
import (
|
||
|
"gitee.ltd/lxh/logger/log"
|
||
|
"wireguard-dashboard/utils"
|
||
|
)
|
||
|
|
||
|
type wireguard struct{}
|
||
|
|
||
|
func Wireguard() wireguard {
|
||
|
return wireguard{}
|
||
|
}
|
||
|
|
||
|
// Apply
|
||
|
// @description: 应用配置
|
||
|
// @receiver wireguard
|
||
|
// @return err
|
||
|
func (wireguard) Apply(templateFilePath, configFilePath string, data any) (err error) {
|
||
|
|
||
|
parseTemplate, err := utils.Template().Parse(templateFilePath)
|
||
|
if err != nil {
|
||
|
log.Errorf("解析模板信息失败")
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
err = utils.Template().Execute(parseTemplate, data, configFilePath)
|
||
|
if err != nil {
|
||
|
log.Errorf("应用配置失败: %v", err.Error())
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|