[ Cmii ] [ Octopus ] - reformat agent-go - 1
This commit is contained in:
34
agent-go/a_init/ConfigParser.go
Normal file
34
agent-go/a_init/ConfigParser.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package a_init
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func ParseConfiguration(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
|
||||
}
|
||||
Reference in New Issue
Block a user