package config import ( "fmt" "reflect" "sync" "github.com/BurntSushi/toml" ) var ( config map[string]interface{} once sync.Once ) func loadConfig() { if _, err := toml.DecodeFile("config.toml", &config); err != nil { panic(err) } } func GetConfig() map[string]interface{} { once.Do(loadConfig) // print(config) return config } func PrintConfig(m map[string]interface{}, indent string) { for key, value := range m { switch v := value.(type) { case map[string]interface{}: fmt.Printf("%s%s (type: %s):\n", indent, key, reflect.TypeOf(v)) PrintConfig(v, indent+" ") case []interface{}: fmt.Printf("%s%s:\n", indent, key) for i, item := range v { switch itemValue := item.(type) { case map[string]interface{}: fmt.Printf("%s [%d] (type: %s):\n", indent, i, reflect.TypeOf(itemValue)) PrintConfig(itemValue, indent+" ") default: fmt.Printf("%s [%d] (type: %s): %v\n", indent, i, reflect.TypeOf(itemValue), item) } } default: fmt.Printf("%s%s (type: %s): %v\n", indent, key, reflect.TypeOf(value), value) } } }