This commit is contained in:
parent
ae30e2c0de
commit
d705073188
17
gin/gin.go
17
gin/gin.go
|
|
@ -13,15 +13,18 @@ import (
|
|||
|
||||
func Service(conf *Config) {
|
||||
if conf == nil {
|
||||
conf = &Config{
|
||||
RootPath: "/",
|
||||
Addr: "0.0.0.0",
|
||||
Port: 8080,
|
||||
Ssl: false,
|
||||
SslPem: "server.pem",
|
||||
SslKey: "server.key",
|
||||
conf = &Config{}
|
||||
}
|
||||
if conf.RootPath == "" {
|
||||
conf.RootPath = "/"
|
||||
}
|
||||
if conf.Addr == "" {
|
||||
conf.Addr = "0.0.0.0"
|
||||
}
|
||||
if conf.Port == 0 {
|
||||
conf.Port = 8080
|
||||
}
|
||||
|
||||
go func() {
|
||||
router := gin.New()
|
||||
routerSetup(router, &conf.RootPath)
|
||||
|
|
|
|||
|
|
@ -18,11 +18,4 @@ func routerSetup(router *gin.Engine, rootpath *string) {
|
|||
r.POST(`/login`)
|
||||
r.POST(`/forgot`)
|
||||
}
|
||||
|
||||
ug := router.Group(`/user`)
|
||||
{
|
||||
ug.GET(`/choose/:orgid`)
|
||||
ug.GET(`/detail`)
|
||||
ug.POST(`/update`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,31 @@ type Config struct {
|
|||
func Init(config *Config) {
|
||||
if config == nil {
|
||||
config = &Config{
|
||||
ConnString: "root:root@tcp(127.0.0.1:3306)/sample?charset=utf8&parseTime=True&loc=Local",
|
||||
ConnMaxLifetime: 1,
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
}
|
||||
}
|
||||
if config.ConnString == "" {
|
||||
config.ConnString = "root:root@tcp(127.0.0.1:3306)/mysql?charset=utf8&parseTime=True&loc=Local"
|
||||
}
|
||||
if config.ConnMaxLifetime < 1 {
|
||||
config.ConnMaxLifetime = 1
|
||||
}
|
||||
if config.ConnMaxLifetime > 6 {
|
||||
config.ConnMaxLifetime = 6
|
||||
}
|
||||
if config.MaxIdleConns < 1 {
|
||||
config.MaxIdleConns = 1
|
||||
}
|
||||
if config.MaxIdleConns > 50 {
|
||||
config.MaxIdleConns = 50
|
||||
}
|
||||
if config.MaxOpenConns < 1 {
|
||||
config.MaxOpenConns = 1
|
||||
}
|
||||
if config.MaxOpenConns > 500 {
|
||||
config.MaxOpenConns = 500
|
||||
}
|
||||
_conf = config
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +63,7 @@ func New() (*gorm.DB, error) {
|
|||
}
|
||||
|
||||
if _conf == nil {
|
||||
return nil, errors.New("组件未初始化,请执行Init!")
|
||||
return nil, errors.New("组件未初始化,请执行Init!")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
|
|||
Loading…
Reference in New Issue