Initial dumb servers
This commit is contained in:
28
server/config/new.go
Normal file
28
server/config/new.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user