35 lines
623 B
Go
35 lines
623 B
Go
package a_init
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func parseOctopusAgentConf(configFileName string) *viper.Viper {
|
|
|
|
agentConfig := parseAgentConfigFile(configFileName, nil)
|
|
|
|
return agentConfig
|
|
}
|
|
|
|
func parseAgentConfigFile(configFileName string, v *viper.Viper) *viper.Viper {
|
|
|
|
// 使用Viper框架读取
|
|
if v == nil {
|
|
v = viper.New()
|
|
}
|
|
|
|
// 设置配置文件路径和名称
|
|
v.SetConfigName(configFileName)
|
|
v.AddConfigPath(".")
|
|
v.SetConfigType("yaml")
|
|
|
|
// 读取默认的总配置文件
|
|
err := v.ReadInConfig()
|
|
if err != nil {
|
|
panic(fmt.Errorf("fatal error config file: %s", err))
|
|
}
|
|
|
|
return v
|
|
}
|