-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrouter.go
More file actions
43 lines (41 loc) · 1.4 KB
/
router.go
File metadata and controls
43 lines (41 loc) · 1.4 KB
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
// Package router
// @Description:
// @Author AN 2023-12-06 23:16:19
package router
import (
taskApi "fiber/app/api/task"
userApi "fiber/app/api/user"
businessError "fiber/error"
"fiber/global"
"fiber/middleware"
"fiber/resultVo"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/monitor"
"time"
)
func AppRouter(app *fiber.App) {
app.Get("/metrics", monitor.New(monitor.Config{Title: "GoApp Monitor", Refresh: 2 * time.Second}))
app.Get("/_startup", func(ctx *fiber.Ctx) error {
global.BLog.Infof("hello")
return ctx.JSON(resultVo.Success("ok", ctx), fiber.MIMEApplicationJSONCharsetUTF8)
})
app.Get("/_healthz", func(ctx *fiber.Ctx) error {
return ctx.JSON(resultVo.Success("success", ctx), fiber.MIMEApplicationJSONCharsetUTF8)
})
app.Post("/task/testCheck", taskApi.TestCheck)
app.Get("/user/count", userApi.GetUser)
// 需要登录鉴权的路由
apiRoute := app.Group("", middleware.AuthMiddleware())
apiRoute.Get("/userInfo", func(ctx *fiber.Ctx) error {
return ctx.JSON(resultVo.Success(nil, ctx), fiber.MIMEApplicationJSONCharsetUTF8)
})
// 其他
app.Get("/", func(ctx *fiber.Ctx) error {
return ctx.JSON(resultVo.Success(nil, ctx), fiber.MIMEApplicationJSONCharsetUTF8)
})
// 404返回
app.Use(func(c *fiber.Ctx) error {
return c.JSON(resultVo.Fail(businessError.New(businessError.NOT_FOUND), c), fiber.MIMEApplicationJSONCharsetUTF8)
})
// 这个后面不要写
}