Skip to content

Commit

Permalink
CartService: Add health check endpoint and update routes
Browse files Browse the repository at this point in the history
Added a new HealthZ endpoint in the Cart Service that responds to HTTP GET requests with a 200 status. Also restructured the existing routes for clarity and better organization, prefixing all cart-related endpoints with '/cart'. Finally, updated the .http file to reflect these changes.
  • Loading branch information
alphayax committed Dec 1, 2023
1 parent 3c5ed3f commit 88f1e20
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
18 changes: 13 additions & 5 deletions cart-service/cart-service.http
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
GET http://localhost:8081/1/
GET http://localhost:8080/
Accept: application/json

###
PUT http://localhost:8081/1/
### Health probe
GET http://localhost:8080/healthz
Accept: application/json

### Get cart with id=1
GET http://localhost:8081/cart/1/
Accept: application/json

### Update cart with id=1
PUT http://localhost:8081/cart/1/
Content-Type: application/json

{
"items": ["1", "2", "3"]
}

###
DELETE http://localhost:8081/1/
### Delete cart with id=1
DELETE http://localhost:8081/cart/1/
Accept: application/json
10 changes: 10 additions & 0 deletions cart-service/handler/HealthZ.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package handler

import (
"github.com/gin-gonic/gin"
"net/http"
)

func HealthZ(c *gin.Context) {
c.Status(http.StatusOK)
}
13 changes: 10 additions & 3 deletions cart-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ func loadApiServer() {
MaxAge: 12 * time.Hour,
}))

Router.GET("/:cartId/", handler.GetCart)
Router.PUT("/:cartId/", handler.UpdateCart)
Router.DELETE("/:cartId/", handler.DeleteCart)
Router.Use(
gin.LoggerWithWriter(gin.DefaultWriter, "/healthz"),
gin.Recovery(),
)

Router.GET("/", handler.HealthZ)
Router.GET("/healthz", handler.HealthZ)
Router.GET("/cart/:cartId/", handler.GetCart)
Router.PUT("/cart/:cartId/", handler.UpdateCart)
Router.DELETE("/cart/:cartId/", handler.DeleteCart)

listenAddress := viper.GetString("listen")
err := Router.Run(listenAddress)
Expand Down

0 comments on commit 88f1e20

Please sign in to comment.