-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (41 loc) · 1016 Bytes
/
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
package main
import (
"context"
"github.com/gin-gonic/gin"
appApi "github.com/maxiloEmmmm/diy-datav/api"
"github.com/maxiloEmmmm/diy-datav/pkg/app"
"github.com/maxiloEmmmm/diy-datav/pkg/permission"
"github.com/maxiloEmmmm/go-web/contact"
)
func main() {
ctx := context.Background()
app.Init(ctx)
defer app.Close()
engine := gin.Default()
engine.Use(contact.GinCors())
apiGroup := engine.Group("/api")
auth := apiGroup.Group("")
auth.Use(contact.GinRouteAuth())
auth.Use()
auth.Use(contact.GinCasbin(contact.GinCasbinOption{
Sub: func(c *gin.Context) string {
return app.User(c)
},
Obj: func(context *gin.Context) string {
return (&permission.PRRouter{Path: context.Request.URL.Path}).Key()
},
Act: func(context *gin.Context) string {
return context.Request.Method
},
}))
for _, api := range appApi.Apis {
if api.ShouldAuth() {
api.Handle(auth)
} else {
api.Handle(apiGroup)
}
}
app.Engine = engine
app.InitPermission(ctx, engine)
engine.Run(":8000")
}