diff --git a/cart-service/cart-service.http b/cart-service/cart-service.http index fa3cc19..8738b28 100644 --- a/cart-service/cart-service.http +++ b/cart-service/cart-service.http @@ -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 diff --git a/cart-service/handler/HealthZ.go b/cart-service/handler/HealthZ.go new file mode 100644 index 0000000..a8cdcdb --- /dev/null +++ b/cart-service/handler/HealthZ.go @@ -0,0 +1,10 @@ +package handler + +import ( + "github.com/gin-gonic/gin" + "net/http" +) + +func HealthZ(c *gin.Context) { + c.Status(http.StatusOK) +} diff --git a/cart-service/main.go b/cart-service/main.go index 5af7396..68162d9 100644 --- a/cart-service/main.go +++ b/cart-service/main.go @@ -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)