package serf import ( "fmt" "github.com/spf13/viper" ) type vasystem struct { ServerName string `mapstructure:"serverName"` ServerID string `mapstructure:"analyServerId"` } var Vasystem = &vasystem{} // Init is an exported method that takes the environment starts the viper // (external lib) and returns the configuration struct. func init() { var err error v := viper.New() v.SetConfigType("yaml") v.SetConfigName("pro") v.AddConfigPath("") v.AddConfigPath("../config/") v.AddConfigPath("./config/") v.AddConfigPath("/opt/vasystem/config/") err = v.ReadInConfig() if err != nil { fmt.Println("error on parsing configuration file", err) } read2Conf(v) } func read2Conf(v *viper.Viper) { v.UnmarshalKey("server", Vasystem) fmt.Println("ServerID:", Vasystem.ServerID) }