-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (62 loc) · 1.55 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
package main
import (
"github.com/glebarez/sqlite"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/install"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/middleware"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service"
"github.com/quarkcloudio/quark-go/v2/pkg/builder"
"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
"github.com/quarkcloudio/quark-lite/dashboard"
"github.com/quarkcloudio/quark-lite/layout"
"github.com/quarkcloudio/quark-lite/login"
"github.com/quarkcloudio/quark-lite/model"
"github.com/quarkcloudio/quark-lite/resource"
"gorm.io/gorm"
)
// 自动构建数据库
func migrate() {
// 迁移数据
db.Client.AutoMigrate(
&model.Demo{},
)
// 数据填充
(&model.Demo{}).Seeder()
}
// 注册服务
func providers() []interface{} {
return []interface{}{
&login.Index{},
&layout.Index{},
&dashboard.Index{},
&resource.Demo{},
}
}
func main() {
// 数据库配置信息
dsn := "./data.db"
// 配置资源
config := &builder.Config{
AppKey: "abcdefg",
Providers: append(service.Providers, providers()...),
DBConfig: &builder.DBConfig{
Dialector: sqlite.Open(dsn),
Opts: &gorm.Config{},
},
}
// 实例化对象
b := builder.New(config)
// 静态文件
b.Static("/", "./web/app")
// 自动构建数据库、拉取静态文件
install.Handle()
// 自动构建本地数据库
migrate()
// 后台中间件
b.Use(middleware.Handle)
// 重定向到后台管理
b.GET("/", func(ctx *builder.Context) error {
return ctx.Redirect(301, "/admin/")
})
// 启动服务
b.Run(":3000")
}