Skip to content

Instantly share code, notes, and snippets.

@deluan
Created Sep 8, 2016
Embed
What would you like to do?
Test for multiconfig on Go 1.7
///usr/bin/env go run "$0" "$@"; exit;
package main
import "github.com/koding/multiconfig"
type Server struct {
Name string `required:"true"`
Port int `default:"6060"`
Enabled bool
Users []string
}
func main() {
// Create a new DefaultLoader without or with an initial config file
m := multiconfig.New()
// Get an empty struct for your configuration
serverConf := new(Server)
// Populated the serverConf struct
err := m.Load(serverConf) // Check for error
if err != nil {
println("ERROR:", err.Error)
}
m.MustLoad(serverConf) // Panic's if there is any error
// Access now populated fields
println("Port: ", serverConf.Port) // by default 6060
println("Name: ", serverConf.Name) // "koding"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment