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-10-11 12:25:41 +08:00
|
|
|
"fmt"
|
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-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-07-08 11:39:36 +08:00
|
|
|
)
|
|
|
|
|
2020-10-11 12:25:41 +08:00
|
|
|
var clearPass = ""
|
|
|
|
|
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-11 12:25:41 +08:00
|
|
|
flag.StringVar(&clearPass, "clp", "", "清除用户密码")
|
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-11 12:25:41 +08:00
|
|
|
if clearUPass() {
|
|
|
|
return
|
|
|
|
}
|
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-09 16:59:03 +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
|
|
|
}
|
2020-10-11 12:25:41 +08:00
|
|
|
|
|
|
|
func clearUPass() bool {
|
|
|
|
if clearPass != "" {
|
|
|
|
usr := dbService.FindUserName(clearPass)
|
|
|
|
if usr == nil {
|
|
|
|
fmt.Printf("user(%s) not found\n", clearPass)
|
|
|
|
} else {
|
|
|
|
usr.Pass = ""
|
|
|
|
_, err := comm.Db.Cols("pass").Where("id=?", usr.Id).Update(usr)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("clear password err:" + err.Error())
|
|
|
|
} else {
|
|
|
|
fmt.Println("clear password ok")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|