gokins/main.go

80 lines
1.6 KiB
Go
Raw Normal View History

2020-07-08 10:09:59 +08:00
package main
2020-07-08 11:39:36 +08:00
import (
2020-10-09 16:59:03 +08:00
"flag"
2020-07-08 11:39:36 +08:00
"gokins/comm"
2020-09-30 20:26:50 +08:00
"gokins/core"
2020-10-02 16:04:26 +08:00
"gokins/mgr"
2020-07-08 15:39:23 +08:00
"gokins/route"
2020-10-12 20:00:26 +08:00
"gokins/service"
2020-09-30 20:26:50 +08:00
"gokins/service/dbService"
2020-07-08 15:39:23 +08:00
"os"
"path/filepath"
2020-09-30 20:26:50 +08:00
"github.com/gin-gonic/gin"
2020-10-13 18:01:36 +08:00
_ "time/tzdata"
2020-07-08 11:39:36 +08:00
)
2020-10-12 20:00:26 +08:00
var (
clearPass = ""
mvData = ""
)
2020-10-11 12:25:41 +08:00
2020-07-08 15:39:23 +08:00
func init() {
path, err := os.Executable()
if err != nil {
println("path err:" + err.Error())
return
}
println("path:" + path)
2020-10-09 16:59:03 +08:00
comm.Path = path
2020-07-08 15:39:23 +08:00
dir, err := filepath.Abs(filepath.Dir(path))
if err != nil {
println("dir err:" + err.Error())
return
}
println("dir:" + dir)
2020-10-09 16:59:03 +08:00
flag.StringVar(&comm.Dir, "d", dir, "数据目录")
2020-10-09 17:10:13 +08:00
flag.StringVar(&comm.Host, "bind", ":8030", "绑定地址")
2020-10-13 13:01:39 +08:00
flag.IntVar(&comm.RunTaskLen, "rln", 5, "同时执行的流水线数量")
2020-10-12 20:00:26 +08:00
flag.StringVar(&clearPass, "clp", "", "清除某个用户密码(请先关闭服务在执行)")
flag.StringVar(&mvData, "mvdata", "", "转移某个库数据到本地(目前转移的数据:流水线、流水线插件)")
2020-10-09 16:59:03 +08:00
flag.Parse()
2020-07-08 11:39:36 +08:00
comm.Gin = gin.Default()
2020-07-08 15:39:23 +08:00
}
func main() {
err := comm.InitDb()
if err != nil {
println("InitDb err:" + err.Error())
return
}
2020-10-12 20:00:26 +08:00
if clearPass != "" {
service.ClearUPass(clearPass)
2020-10-11 12:25:41 +08:00
return
}
2020-10-12 20:00:26 +08:00
if mvData != "" {
service.MoveData(mvData)
return
}
runWeb()
}
func runWeb() {
2020-09-30 20:26:50 +08:00
jwtKey := dbService.GetParam("jwt-key")
jkey := jwtKey.GetString("key")
if jkey == "" {
jkey = core.RandomString(32)
jwtKey.Set("key", jkey)
dbService.SetParam("jwt-key", jwtKey)
}
core.JwtKey = jkey
2020-07-08 15:39:23 +08:00
route.Init()
2020-10-02 16:04:26 +08:00
mgr.ExecMgr.Start()
2020-10-12 20:00:26 +08:00
err := comm.Gin.Run(comm.Host)
2020-07-08 12:05:33 +08:00
if err != nil {
2020-07-08 15:39:23 +08:00
println("gin run err:" + err.Error())
2020-07-08 12:05:33 +08:00
}
2020-10-02 16:04:26 +08:00
mgr.Cancel()
2020-07-08 10:09:59 +08:00
}