-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (58 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"os/signal"
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // web framework adapter
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql" // sql driver
_ "github.com/GoAdminGroup/themes/adminlte" // ui theme
_ "github.com/GoAdminGroup/themes/adminlte/separation"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/chartjs"
"github.com/gin-gonic/gin"
"AssetInfo/models"
"AssetInfo/pages"
"AssetInfo/tables"
)
func main() {
startServer()
}
func startServer() {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
r := gin.Default()
template.AddComp(chartjs.NewChart())
eng := engine.Default()
if err := eng.AddConfigFromYAML("./config.yml").
AddGenerators(tables.Generators).
Use(r); err != nil {
panic(err)
}
r.Static("/uploads", "./uploads")
eng.HTML("GET", "/admin", pages.GetDashBoard)
//eng.HTMLFile(
// "GET",
// "/admin/hello",
// "./html/hello.tmpl",
// map[string]interface{}{
// "msg": "Hello world",
//})
//eng.Data(
// "GET",
// "/admin/data/:id",
// handlers.AutoCheck,
//)
models.Init(eng.MysqlConnection())
var serve string
flag.StringVar(&serve, "serve", ":80", "服务地址及端口")
flag.Parse()
_ = r.Run(serve)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
log.Print("closing database connection")
eng.MysqlConnection().Close()
}