diff --git a/config/config.go b/config/config.go new file mode 100644 index 000000000..103d8e3d2 --- /dev/null +++ b/config/config.go @@ -0,0 +1,53 @@ +package config + +import ( + "flag" + "log" + "io/ioutil" + "launchpad.net/goyaml" +) + +var config map[string]interface{} + +func GetSafe(key string) (interface{}, bool) { + value, ok := config[key] + return value, ok +} + +func Get(key string) interface{} { + return config[key] +} + +func GetInt(key string) int { + value, ok := GetSafe(key) + if ok { + value_int, ok := value.(int) + if ok { + return value_int + } + } + return 0 +} + +func GetString(key string) string { + value, ok := GetSafe(key) + if ok { + value_string, ok := value.(string) + if ok { + return value_string + } + } + return "" +} + +func init() { + log.Println("Start config") + config = make(map[string]interface{}) + config_file := flag.String("config", "pilosa.yaml", "Path to config file.") + flag.Parse() + data, err := ioutil.ReadFile(*config_file) + if err != nil { + log.Fatal("Problem with config file. ", err) + } + goyaml.Unmarshal(data, &config) +} diff --git a/deps.json b/deps.json index 4fbea9c4a..1001f0137 100644 --- a/deps.json +++ b/deps.json @@ -19,6 +19,11 @@ "version": "87bcc4729f2c5a08d2513ad10684c6bbd256380f", "type": "git" }, + "goyaml": { + "repo": "launchpad.net/goyaml", + "version": "50", + "type": "bzr" + }, "lru": { "repo": "github.com/golang/groupcache/lru", "version": "d781998583680cda80cf61e0b37dd0cd8da2eb52",