Skip to content

Instantly share code, notes, and snippets.

@deluan
Created September 8, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deluan/4602735f4cca6c5b1d6e10d7c22b5152 to your computer and use it in GitHub Desktop.
Save deluan/4602735f4cca6c5b1d6e10d7c22b5152 to your computer and use it in GitHub Desktop.
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