func main() { if flag.NArg() < 1 { flag.Usage() } for _, f := range flag.Args() { var tmp interface{} md, err := toml.DecodeFile(f, &tmp) if err != nil { log.Fatalf("Error in '%s': %s", f, err) } if flagTypes { printTypes(md) } } }
func main() { var config tomlConfig if _, err := toml.DecodeFile("example.toml", &config); err != nil { fmt.Println(err) return } fmt.Printf("Title: %s\n", config.Title) fmt.Printf("Owner: %s (%s, %s), Born: %s\n", config.Owner.Name, config.Owner.Org, config.Owner.Bio, config.Owner.DOB) fmt.Printf("Database: %s %v (Max conn. %d), Enabled? %v\n", config.DB.Server, config.DB.Ports, config.DB.ConnMax, config.DB.Enabled) for serverName, server := range config.Servers { fmt.Printf("Server: %s (%s, %s)\n", serverName, server.IP, server.DC) } fmt.Printf("Client data: %v\n", config.Clients.Data) fmt.Printf("Client hosts: %v\n", config.Clients.Hosts) }
// Loads configuration from a file. func (c *Config) LoadFile(path string) error { _, err := toml.DecodeFile(path, &c) return err }