Skip to content

Instantly share code, notes, and snippets.

@chadlung
Created October 13, 2014 22:18
Show Gist options
  • Save chadlung/aafce18f21c1f05a4b77 to your computer and use it in GitHub Desktop.
Save chadlung/aafce18f21c1f05a4b77 to your computer and use it in GitHub Desktop.
Viper Configuration Example
{
"msg": "Hello World"
}
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigName("config")
//viper.AddConfigPath("/Users/chadlung/GoProjects/src/github.com/chadlung/viper-example")
err := viper.ReadInConfig()
if err != nil {
fmt.Println("No configuration file loaded - using defaults")
}
// If no config is found, use the default(s)
viper.SetDefault("msg", "Hello World (default)")
theMessage := viper.GetString("msg")
fmt.Printf("\n%s\n\n", theMessage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment