oauth2/oauth2server/config/config.go

57 lines
1.4 KiB
Go
Executable File

package config
import (
"fmt"
"gogs.inhome.blapointe.com/local/args"
"os"
"strings"
)
var (
Port string
Store string
StoreAddr string
StoreUser string
StorePass string
SecretA string
SecretB string
UserRegistration bool
)
func init() {
Refresh()
}
func Refresh() {
if strings.Contains(fmt.Sprint(os.Args), "-test") {
return
}
defer func() {
if err := recover(); err != nil {
panic(err)
}
}()
as := args.NewArgSet()
as.Append(args.STRING, "port", "port to listen on", "23456")
as.Append(args.STRING, "secretA", "secret A", "secret")
as.Append(args.STRING, "secretB", "secret B", "secret")
as.Append(args.STRING, "store", "type of DB", "map")
as.Append(args.STRING, "storeAddr", "addr of DB", "/tmp/oauth2server.db")
as.Append(args.STRING, "storeUser", "user of DB", "")
as.Append(args.STRING, "storePass", "pass of DB", "")
as.Append(args.BOOL, "users", "allow user registration", false)
if err := as.Parse(); err != nil {
panic(err)
}
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
Store = as.Get("store").GetString()
StoreAddr = as.Get("storeaddr").GetString()
StoreUser = as.Get("storeuser").GetString()
StorePass = as.Get("storepass").GetString()
SecretA = as.Get("secreta").GetString()
SecretB = as.Get("secretb").GetString()
UserRegistration = as.Get("users").GetBool() || Store == "map"
}