github.com/HXSecurity/DongTai-agent-go@v0.4.2/global/config.go (about) 1 package global 2 3 import ( 4 "flag" 5 "fmt" 6 "github.com/HXSecurity/DongTai-agent-go/model" 7 "gopkg.in/yaml.v3" 8 "io/ioutil" 9 ) 10 11 var Config model.Config 12 13 func InitViper() { 14 config, err := ioutil.ReadFile("dongtai-go-agent-config.yaml") 15 fmt.Println(string(config)) 16 if err != nil { 17 fmt.Println(err) 18 return 19 } 20 err = yaml.Unmarshal(config, &Config) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 var version string 27 var name string 28 var auto bool 29 30 flag.StringVar(&version, "DongtaiGoProjectVersion", "v1.0.0", "Project Version") 31 flag.StringVar(&name, "DongtaiGoProjectName", "GO Project", "Project Name") 32 flag.BoolVar(&auto, "DongtaiGoProjectCreate", true, "Auto Create Project") 33 flag.Parse() 34 if version != "v1.0.0" { 35 Config.DongtaiGoProjectVersion = version 36 } 37 if name != "GO Project" { 38 Config.DongtaiGoProjectName = name 39 } 40 if auto != true { 41 Config.DongtaiGoProjectCreate = auto 42 } 43 fmt.Println(Config) 44 }