mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
Add config module.
This commit is contained in:
parent
258c990fd1
commit
2aade5c2a9
2 changed files with 58 additions and 0 deletions
53
config/config.go
Normal file
53
config/config.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue