Rssmon2/config/config.go

31 lines
457 B
Go

package config
import (
"flag"
"os"
"strings"
)
const cdbpath = "DBPath"
type Config struct {
DBPath string
}
func New() *Config {
lookups := make(map[string]*string)
add(cdbpath, "./db", lookups)
flag.Parse()
return &Config{
DBPath: *lookups[cdbpath],
}
}
func add(key string, value string, lookups map[string]*string) {
env := os.Getenv(strings.ToUpper(key))
if env != "" {
value = env
}
lookups[key] = flag.String(key, value, "")
}