forked from gitslagga/gitbitex-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
125 lines (104 loc) · 3.51 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"context"
"errors"
"fmt"
"github.com/gitslagga/gitbitex-admin/models"
"log"
"net/http"
"os"
"os/signal"
"time"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
_ "github.com/GoAdminGroup/themes/adminlte"
_ "github.com/GoAdminGroup/themes/sword"
"github.com/GoAdminGroup/components/echarts"
ada "github.com/GoAdminGroup/go-admin/adapter/gin"
adminContext "github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/chartjs"
"github.com/GoAdminGroup/go-admin/template/types"
"github.com/gin-gonic/gin"
"github.com/gitslagga/gitbitex-admin/login"
"github.com/gitslagga/gitbitex-admin/pages"
"github.com/gitslagga/gitbitex-admin/tables"
)
func main() {
//gin.SetMode(gin.ReleaseMode)
r := gin.Default()
eng := engine.Default()
var loginComps = map[string]template.Component{
"default": login.Get(),
}
template.AddLoginComp(loginComps["default"])
template.AddComp(chartjs.NewChart())
template.AddComp(echarts.NewChart())
cfg := config.ReadFromJson("./config.json")
cfg.AddUpdateProcessFn(func(values form.Values) (values2 form.Values, e error) {
if values.Get("login_title") != "GO111MODULE" {
return nil, errors.New("不允许的操作")
}
return values, nil
})
if err := eng.AddConfig(cfg).
AddGenerators(tables.Generators).
ResolveMysqlConnection(models.SetConn).
Use(r); err != nil {
panic(err)
}
r.Static("/uploads", "./uploads")
// you can custom your pages like:
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407", ada.Content(func(ctx *gin.Context) (panel types.Panel, e error) {
if config.GetTheme() == "adminlte" {
return pages.GetDashBoardContent(ctx)
} else {
return pages.GetDashBoard2Content(ctx)
}
}))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/issue", ada.Content(pages.GetIssueContent))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/holding", ada.Content(pages.GetHoldingContent))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/promote", ada.Content(pages.GetPromoteContent))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/echarts", ada.Content(pages.GetDashBoard3Content))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/table", ada.Content(pages.GetTableContent))
r.GET("/0x82d2658D3fF713fbDA59f39aEA584975D7442407/form1", ada.Content(pages.GetForm1Content))
eng.Data("POST", "/admin/form/update", func(ctx *adminContext.Context) {
fmt.Println("ctx.PostForm()", ctx.PostForm())
ctx.PjaxUrl("/admin")
})
eng.Data("POST", "/admin/popup/form", func(ctx *adminContext.Context) {
ctx.JSON(http.StatusOK, map[string]interface{}{
"code": 200,
"msg": "ok",
"data": map[string]string{
"url": "/admin/info/profile",
},
})
})
//r.GET("/", func(ctx *gin.Context) {
// ctx.Redirect(http.StatusMovedPermanently, "/admin")
//})
models.Init(eng.MysqlConnection())
srv := &http.Server{
Addr: ":80",
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")
log.Print("closing database connection")
eng.MysqlConnection().Close()
}