Created
October 13, 2014 22:18
-
-
Save chadlung/aafce18f21c1f05a4b77 to your computer and use it in GitHub Desktop.
Viper Configuration Example
This file contains hidden or 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
{ | |
"msg": "Hello World" | |
} |
This file contains hidden or 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
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