2020-07-08 10:09:59 +08:00
|
|
|
package main
|
|
|
|
|
2020-07-08 11:39:36 +08:00
|
|
|
import (
|
|
|
|
"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
|
|
|
"net/http"
|
|
|
|
"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-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)
|
|
|
|
dir, err := filepath.Abs(filepath.Dir(path))
|
|
|
|
if err != nil {
|
|
|
|
println("dir err:" + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println("dir:" + dir)
|
|
|
|
comm.Path = path
|
|
|
|
comm.Dir = dir
|
2020-07-08 11:39:36 +08:00
|
|
|
comm.Gin = gin.Default()
|
2020-07-08 15:39:23 +08:00
|
|
|
if len(os.Args) > 1 && os.Args[1] == "tests" {
|
|
|
|
comm.Dir = "."
|
|
|
|
}
|
|
|
|
comm.Gin.StaticFS("/css", http.Dir(comm.Dir+"/ui/css"))
|
|
|
|
comm.Gin.StaticFS("/js", http.Dir(comm.Dir+"/ui/js"))
|
2020-10-04 18:51:55 +08:00
|
|
|
comm.Gin.StaticFS("/img", http.Dir(comm.Dir+"/ui/img"))
|
|
|
|
comm.Gin.StaticFS("/fonts", http.Dir(comm.Dir+"/ui/fonts"))
|
2020-10-09 14:20:00 +08:00
|
|
|
comm.Gin.StaticFile("/", comm.Dir+"/ui/index.html")
|
2020-07-08 15:39:23 +08:00
|
|
|
comm.Gin.StaticFile("/index.html", comm.Dir+"/ui/index.html")
|
|
|
|
comm.Gin.StaticFile("/favicon.ico", comm.Dir+"/ui/favicon.ico")
|
|
|
|
/*comm.Gin.FuncMap = template.FuncMap{
|
2020-07-08 11:39:36 +08:00
|
|
|
"AppName": func() string {
|
|
|
|
return "mine app"
|
|
|
|
},
|
|
|
|
}
|
2020-07-08 15:39:23 +08:00
|
|
|
comm.Gin.LoadHTMLGlob("view/*")*/
|
2020-07-08 12:05:33 +08:00
|
|
|
//comm.FileView=true
|
2020-07-08 15:39:23 +08:00
|
|
|
/*comm.Gin.SetHTMLTemplate(utils.HtmlSource)
|
|
|
|
err := utils.InitHtmls()
|
|
|
|
if err != nil {
|
|
|
|
println("InitHtmls err:" + err.Error())
|
|
|
|
return
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
func main() {
|
|
|
|
err := comm.InitDb()
|
|
|
|
if err != nil {
|
|
|
|
println("InitDb err:" + err.Error())
|
|
|
|
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-09-29 22:35:32 +08:00
|
|
|
err = comm.Gin.Run(":8030")
|
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
|
|
|
}
|