Initial dumb servers

This commit is contained in:
Bel LaPointe
2019-03-14 14:43:02 -06:00
commit 1f679f4c06
10 changed files with 381 additions and 0 deletions

28
server/config/new.go Normal file
View 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
}