-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
97 lines (80 loc) · 2.17 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"context"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
"time"
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // web framework adapter
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite" // sql driver
_ "github.com/GoAdminGroup/themes/sword/separation" // ui theme
"github.com/GoAdminGroup/example/models"
"github.com/GoAdminGroup/example/pages"
"github.com/GoAdminGroup/example/tables"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/chartjs"
"github.com/gin-gonic/gin"
)
func main() {
startServer()
}
func startServer() {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
r := gin.Default()
eng := engine.Default()
template.AddComp(chartjs.NewChart())
//cfg := config.Config{
// Databases: config.DatabaseList{
// "default": {
// Host: "127.0.0.1",
// Port: "3306",
// User: "root",
// Pwd: "root",
// Name: "go-admin",
// MaxIdleCon: 50,
// MaxOpenCon: 150,
// Driver: db.DriverMysql,
// },
// },
// UrlPrefix: "admin",
// IndexUrl: "/",
// Debug: true,
// Language: language.CN,
//}
if err := eng.AddConfigFromYAML("./config.yml").
AddGenerators(tables.Generators).
AddGenerator("external", tables.GetExternalTable).
Use(r); err != nil {
panic(err)
}
models.Init(eng.SqliteConnection())
r.Static("/uploads", "./uploads")
eng.HTML("GET", "/admin", pages.DashboardPage)
eng.HTML("GET", "/admin/form", pages.GetFormContent)
eng.HTML("GET", "/admin/table", pages.GetTableContent)
eng.HTMLFile("GET", "/admin/hello", "./html/hello.tmpl", map[string]interface{}{
"msg": "Hello world",
})
srv := &http.Server{
Addr: ":9033",
Handler: r,
}
go func() {
if err := srv.ListenAndServe(); err != nil {
log.Printf("listen: %s\n", err)
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
log.Println("Server exiting")
}