Skip to content

Commit

Permalink
chore: update healthz's return val
Browse files Browse the repository at this point in the history
Signed-off-by: daz-3ux <[email protected]>
  • Loading branch information
Daz-3ux committed Oct 17, 2023
1 parent fae5bb9 commit a1342eb
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions internal/dazBlog/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a1342eb

Please sign in to comment.