From aebdb733a8382c34d27a61e44568d8989b09f93e Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 12 Dec 2024 11:29:46 +0100 Subject: [PATCH] Add endpoint for health checking the server (ping) --- cmd/serverFunc.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 7381b2f..f818894 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -98,12 +98,13 @@ func server() { gin.SetMode(gin.ReleaseMode) r := gin.Default() - r.GET("/", helloWorld) + //r.GET("/", helloWorld) // TODO: Have fun creating new endpoints r.GET("/api/user", getUsers) r.GET("/api/user/:userid", getUser) r.POST("/api/user", createUser) r.DELETE("/api/user/:userid", deleteUser) + r.GET("/api/ping", ping) r.Run(":" + ListenPort) } @@ -225,8 +226,6 @@ func getUsers(c *gin.Context) { c.IndentedJSON(http.StatusOK, setResponse(users, true)) } -func helloWorld(c *gin.Context) { - ua := c.Request.UserAgent() - message := fmt.Sprintf("Hello %v!\n", ua) - c.String(http.StatusOK, message) +func ping(c *gin.Context) { + c.IndentedJSON(http.StatusOK, setResponse("Pong!", true)) }