Created
September 8, 2016 22:08
-
-
Save deluan/4602735f4cca6c5b1d6e10d7c22b5152 to your computer and use it in GitHub Desktop.
Test for multiconfig on Go 1.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///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