package config import ( "github.com/spf13/viper" "log" ) type server struct { EsServerIp string `mapstructure: "esServerIp"` EsServerPort string `mapstructure: "esServerPort"` CoreBaseUnit string `mapstructure: "coreBaseUnit"` TimeOut string `mapstructure: "timeOut"` ScriptPath string `mapstructure: scriptPath` } type elastic struct { IndexName string `mapstructure: "indexName"` IndexType string `mapstructure: "indexType"` } var Server = &server{} var BasicFS = &elastic{} func Init(env string) { var err error viper.SetConfigType("yaml") viper.SetConfigName(env) viper.AddConfigPath("/opt/vasystem/config") err = viper.ReadInConfig() if err != nil { log.Fatal("error on parsing configuration file", err) } viper.UnmarshalKey("server", Server) viper.UnmarshalKey("elastic.basicFS", BasicFS) //fmt.Println(AiOcean) //fmt.Println(BasicFS) }