Created
May 7, 2015 21:38
-
-
Save etdebruin/eb6bf8c5d21063fbedec to your computer and use it in GitHub Desktop.
Config package
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
package config | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
type ConfigHash map[string]string | |
var Config ConfigHash | |
func ReadConfig(name string) string { | |
if Config[name] == "" { | |
LoadConfig() | |
} | |
return Config[name] | |
} | |
func LoadConfig() { | |
file, err := ioutil.ReadFile("./config.json") | |
if err != nil { | |
fmt.Printf("File error: %v\n", err) | |
os.Exit(1) | |
} | |
json.Unmarshal(file, &Config) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment