From a1342eb17a809fc594e52c76a0edec11ed774ac7 Mon Sep 17 00:00:00 2001 From: daz-3ux Date: Tue, 17 Oct 2023 18:39:00 +0800 Subject: [PATCH] chore: update healthz's return val Signed-off-by: daz-3ux --- internal/dazBlog/router.go | 134 ++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/internal/dazBlog/router.go b/internal/dazBlog/router.go index d9087db..3c190a4 100644 --- a/internal/dazBlog/router.go +++ b/internal/dazBlog/router.go @@ -6,83 +6,83 @@ package dazBlog import ( - "github.com/gin-contrib/pprof" - "github.com/gin-gonic/gin" + "github.com/gin-contrib/pprof" + "github.com/gin-gonic/gin" - "github.com/Daz-3ux/dBlog/internal/pkg/errno" + "github.com/Daz-3ux/dBlog/internal/pkg/errno" - "github.com/Daz-3ux/dBlog/internal/dazBlog/controller/v1/post" - "github.com/Daz-3ux/dBlog/internal/dazBlog/controller/v1/user" - "github.com/Daz-3ux/dBlog/internal/dazBlog/store" - "github.com/Daz-3ux/dBlog/internal/pkg/core" - "github.com/Daz-3ux/dBlog/internal/pkg/log" - mw "github.com/Daz-3ux/dBlog/internal/pkg/middleware" - "github.com/Daz-3ux/dBlog/pkg/auth" + "github.com/Daz-3ux/dBlog/internal/dazBlog/controller/v1/post" + "github.com/Daz-3ux/dBlog/internal/dazBlog/controller/v1/user" + "github.com/Daz-3ux/dBlog/internal/dazBlog/store" + "github.com/Daz-3ux/dBlog/internal/pkg/core" + "github.com/Daz-3ux/dBlog/internal/pkg/log" + mw "github.com/Daz-3ux/dBlog/internal/pkg/middleware" + "github.com/Daz-3ux/dBlog/pkg/auth" ) func installRouters(g *gin.Engine) error { - // register 404 handler - g.LoadHTMLGlob("internal/resource/404.html") - g.NoRoute(func(c *gin.Context) { - log.C(c).Errorw("Page not found", "url:", c.Request.URL) - core.WriteResponse(c, errno.ErrPageNotFound, nil) - }) + // register 404 handler + g.LoadHTMLGlob("internal/resource/404.html") + g.NoRoute(func(c *gin.Context) { + log.C(c).Errorw("Page not found", "url:", c.Request.URL) + core.WriteResponse(c, errno.ErrPageNotFound, nil) + }) - // register /healthz handler - g.GET("/healthz", func(c *gin.Context) { - log.C(c).Infow("Healthz function called") - core.WriteResponse(c, nil, map[string]string{"status": "ok"}) - }) + // register /healthz handler + g.GET("/healthz", func(c *gin.Context) { + log.C(c).Infow("Healthz function called") + core.WriteResponse(c, nil, map[string]string{"status": "OK"}) + }) - pprof.Register(g) + pprof.Register(g) - authz, err := auth.NewAuthz(store.S.DB()) - if err != nil { - return err - } + authz, err := auth.NewAuthz(store.S.DB()) + if err != nil { + return err + } - uc := user.NewUserController(store.S, authz) - pc := post.NewPostController(store.S) + uc := user.NewUserController(store.S, authz) + pc := post.NewPostController(store.S) - g.POST("/login", uc.Login) - // create v1 route group - v1 := g.Group("/v1") - { - // create user's route group - userv1 := v1.Group("/users") - { - // create user - userv1.POST("", uc.Create) - // change user password - userv1.PUT(":name/change-password", uc.ChangePassword) - // middleware - userv1.Use(mw.Authn(), mw.Authz(authz)) - // get user info - userv1.GET(":name", uc.Get) - // update user info - userv1.PUT(":name", uc.Update) - // list all users, only root user can access - userv1.GET("", uc.List) - // delete user - userv1.DELETE(":name", uc.Delete) - } + g.POST("/login", uc.Login) + // create v1 route group + v1 := g.Group("/v1") + { + // create user's route group + userv1 := v1.Group("/users") + { + // create user + userv1.POST("", uc.Create) + // change user password + userv1.PUT(":name/change-password", uc.ChangePassword) + // middleware + userv1.Use(mw.Authn(), mw.Authz(authz)) + // get user info + userv1.GET(":name", uc.Get) + // update user info + userv1.PUT(":name", uc.Update) + // list all users, only root user can access + userv1.GET("", uc.List) + // delete user + userv1.DELETE(":name", uc.Delete) + } - postv1 := v1.Group("/posts", mw.Authn()) - { - // create post - postv1.POST("", pc.Create) - // get post - postv1.GET(":postID", pc.Get) - // update post - postv1.PUT(":postID", pc.Update) - // delete post - postv1.DELETE(":postID", pc.Delete) - // batch delete posts - postv1.DELETE("", pc.DeleteCollection) - // list posts - postv1.GET("", pc.List) - } - } + postv1 := v1.Group("/posts", mw.Authn()) + { + // create post + postv1.POST("", pc.Create) + // get post + postv1.GET(":postID", pc.Get) + // update post + postv1.PUT(":postID", pc.Update) + // delete post + postv1.DELETE(":postID", pc.Delete) + // batch delete posts + postv1.DELETE("", pc.DeleteCollection) + // list posts + postv1.GET("", pc.List) + } + } - return nil + return nil }