forked from GoAdminGroup/go-admin
/
beego.go
90 lines (69 loc) · 2.22 KB
/
beego.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
package beego
import (
// add beego adapter
_ "github.com/marerm27/go-admin/adapter/beego"
"github.com/marerm27/go-admin/modules/config"
"github.com/marerm27/go-admin/modules/language"
"github.com/marerm27/go-admin/plugins/admin/modules/table"
"github.com/marerm27/themes/adminlte"
// add mysql driver
_ "github.com/marerm27/go-admin/modules/db/drivers/mysql"
// add postgresql driver
_ "github.com/marerm27/go-admin/modules/db/drivers/postgres"
// add sqlite driver
_ "github.com/marerm27/go-admin/modules/db/drivers/sqlite"
// add mssql driver
_ "github.com/marerm27/go-admin/modules/db/drivers/mssql"
// add adminlte ui theme
_ "github.com/marerm27/themes/adminlte"
"net/http"
"os"
"github.com/marerm27/go-admin/engine"
"github.com/marerm27/go-admin/plugins/admin"
"github.com/marerm27/go-admin/plugins/example"
"github.com/marerm27/go-admin/template"
"github.com/marerm27/go-admin/template/chartjs"
"github.com/marerm27/go-admin/tests/tables"
"github.com/astaxie/beego"
)
func newHandler() http.Handler {
app := beego.NewApp()
eng := engine.Default()
adminPlugin := admin.NewAdmin(tables.Generators)
adminPlugin.AddGenerator("user", tables.GetUserTable)
examplePlugin := example.NewExample()
if err := eng.AddConfigFromJSON(os.Args[len(os.Args)-1]).
AddPlugins(adminPlugin, examplePlugin).Use(app); err != nil {
panic(err)
}
template.AddComp(chartjs.NewChart())
eng.HTML("GET", "/admin", tables.GetContent)
beego.BConfig.Listen.HTTPAddr = "127.0.0.1"
beego.BConfig.Listen.HTTPPort = 9087
return app.Handlers
}
func NewHandler(dbs config.DatabaseList, gens table.GeneratorList) http.Handler {
app := beego.NewApp()
eng := engine.Default()
adminPlugin := admin.NewAdmin(gens)
if err := eng.AddConfig(config.Config{
Databases: dbs,
UrlPrefix: "admin",
Store: config.Store{
Path: "./uploads",
Prefix: "uploads",
},
Language: language.EN,
IndexUrl: "/",
Debug: true,
ColorScheme: adminlte.ColorschemeSkinBlack,
}).
AddPlugins(adminPlugin).Use(app); err != nil {
panic(err)
}
template.AddComp(chartjs.NewChart())
eng.HTML("GET", "/admin", tables.GetContent)
beego.BConfig.Listen.HTTPAddr = "127.0.0.1"
beego.BConfig.Listen.HTTPPort = 9087
return app.Handlers
}