29 lines
623 B
Go
29 lines
623 B
Go
package config
|
|
|
|
import (
|
|
"local/storage"
|
|
"os"
|
|
)
|
|
|
|
func New() error {
|
|
config = Config{
|
|
db: orEnv(storage.MAP.String(), "DB", "DATABASE"),
|
|
Addr: orEnv("", "ADDR", "FILE"),
|
|
Username: orEnv("", "USER", "USERNAME"),
|
|
Password: orEnv("", "PASS", "PASSWORD"),
|
|
Port: orEnv("21412", "PORT", "LISTEN"),
|
|
}
|
|
DB, err := storage.New(storage.TypeFromString(config.db), config.Addr, config.Username, config.Password)
|
|
config.DB = DB
|
|
return err
|
|
}
|
|
|
|
func orEnv(def, key string, keys ...string) string {
|
|
for _, key := range append(keys, key) {
|
|
if v, ok := os.LookupEnv(key); ok {
|
|
return v
|
|
}
|
|
}
|
|
return def
|
|
}
|