Skip to content

Instantly share code, notes, and snippets.

@etdebruin
Created May 7, 2015 21:38
Show Gist options
  • Save etdebruin/eb6bf8c5d21063fbedec to your computer and use it in GitHub Desktop.
Save etdebruin/eb6bf8c5d21063fbedec to your computer and use it in GitHub Desktop.
Config package
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