forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
29 lines (23 loc) · 759 Bytes
/
router.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
package example
import (
"github.com/chenhg5/go-admin/context"
"github.com/chenhg5/go-admin/modules/auth"
"github.com/chenhg5/go-admin/plugins/admin/controller"
)
func InitRouter(prefix string) *context.App {
app := context.NewApp()
authenticator := auth.SetPrefix(prefix).SetAuthFailCallback(func(ctx *context.Context) {
ctx.Write(302, map[string]string{
"Location": prefix + "/login",
}, ``)
}).SetPermissionDenyCallback(func(ctx *context.Context) {
controller.ShowErrorPage(ctx, "permission denied")
})
app.GET(prefix+"/example", authenticator.Middleware(TestHandler))
if prefix == "" {
app.GET(prefix+"/", authenticator.Middleware(TestHandler))
} else {
app.GET(prefix, authenticator.Middleware(TestHandler))
}
return app
}