gokins/main.go

68 lines
1.5 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 (
"github.com/gin-gonic/gin"
ruisUtil "github.com/mgr9525/go-ruisutil"
"gokins/comm"
2020-07-08 15:39:23 +08:00
"gokins/route"
"net/http"
"os"
"path/filepath"
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"))
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-07-08 12:05:33 +08:00
comm.Gin.Any("/test", func(c *gin.Context) {
2020-07-08 11:39:36 +08:00
data := ruisUtil.NewMap()
data.Set("cont", "你好啊world!")
2020-07-08 15:39:23 +08:00
//utils.html(c, "test.html", data)
c.HTML(200, "test.html", data)
2020-07-08 10:09:59 +08:00
})
2020-07-08 15:39:23 +08:00
route.Init()
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-07-08 10:09:59 +08:00
}