You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oa/cfg/cfg.go

45 lines
1.1 KiB
Go

//
// cfg.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-09-20 16:10:16
// Distributed under terms of the MIT license.
//
package cfg
import (
"github.com/veypi/OneBD/rest"
"github.com/veypi/utils/flags"
"github.com/veypi/utils/logv"
)
type config struct {
rest.RestConf
DSN string `json:"dsn"`
JWT string `json:"jwt"`
}
var Config = &config{}
var CMD = flags.New("oa", "the backend server of oa")
var CfgDump = CMD.SubCommand("cfg", "generate cfg file")
var configFile = CMD.String("f", "./dev.yaml", "the config file")
func init() {
CMD.StringVar(&Config.Host, "h", "0.0.0.0", "host")
CMD.IntVar(&Config.Port, "p", 4000, "port")
CMD.StringVar(&Config.LoggerLevel, "l", "info", "log level")
CMD.StringVar(&Config.DSN, "dsn", "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Local", "data source name")
CMD.Before = func() error {
flags.LoadCfg(*configFile, Config)
CMD.Parse()
logv.SetLevel(logv.AssertFuncErr(logv.ParseLevel(Config.LoggerLevel)))
return nil
}
CfgDump.Command = func() error {
flags.DumpCfg(*configFile, Config)
return nil
}
}