Base project to template
This commit is contained in:
53
config/config.go
Executable file
53
config/config.go
Executable file
@@ -0,0 +1,53 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"local/args"
|
||||
"local/storage"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
Port string
|
||||
OAuthServer string
|
||||
Store storage.DB
|
||||
StoreType string
|
||||
StoreAddr string
|
||||
StoreUser string
|
||||
StorePass string
|
||||
)
|
||||
|
||||
func init() {
|
||||
Refresh()
|
||||
}
|
||||
|
||||
func Refresh() {
|
||||
if strings.Contains(fmt.Sprint(os.Args), " -test") {
|
||||
return
|
||||
}
|
||||
|
||||
as := args.NewArgSet()
|
||||
as.Append(args.STRING, "port", "port to listen on", "49809")
|
||||
as.Append(args.STRING, "oauth", "oauth URL", "")
|
||||
as.Append(args.STRING, "storetype", "storage type", "map")
|
||||
as.Append(args.STRING, "storeaddr", "storage address", "")
|
||||
as.Append(args.STRING, "storeuser", "storage username", "")
|
||||
as.Append(args.STRING, "storepass", "storage password", "")
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
|
||||
OAuthServer = as.Get("oauth").GetString()
|
||||
StoreType = as.Get("storetype").GetString()
|
||||
StoreAddr = as.Get("storeaddr").GetString()
|
||||
StoreUser = as.Get("storeuser").GetString()
|
||||
StorePass = as.Get("storepass").GetString()
|
||||
|
||||
if db, err := storage.New(storage.TypeFromString(StoreType), StoreAddr, StoreUser, StorePass); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
Store = db
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user