Add endpoint for health checking the server (ping)

This commit is contained in:
raul 2024-12-12 11:29:46 +01:00
parent 304eb928eb
commit aebdb733a8
Signed by: raul
GPG Key ID: C1AA797073F17129
1 changed files with 4 additions and 5 deletions

View File

@ -98,12 +98,13 @@ func server() {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
r := gin.Default() r := gin.Default()
r.GET("/", helloWorld) //r.GET("/", helloWorld)
// TODO: Have fun creating new endpoints // TODO: Have fun creating new endpoints
r.GET("/api/user", getUsers) r.GET("/api/user", getUsers)
r.GET("/api/user/:userid", getUser) r.GET("/api/user/:userid", getUser)
r.POST("/api/user", createUser) r.POST("/api/user", createUser)
r.DELETE("/api/user/:userid", deleteUser) r.DELETE("/api/user/:userid", deleteUser)
r.GET("/api/ping", ping)
r.Run(":" + ListenPort) r.Run(":" + ListenPort)
} }
@ -225,8 +226,6 @@ func getUsers(c *gin.Context) {
c.IndentedJSON(http.StatusOK, setResponse(users, true)) c.IndentedJSON(http.StatusOK, setResponse(users, true))
} }
func helloWorld(c *gin.Context) { func ping(c *gin.Context) {
ua := c.Request.UserAgent() c.IndentedJSON(http.StatusOK, setResponse("Pong!", true))
message := fmt.Sprintf("Hello %v!\n", ua)
c.String(http.StatusOK, message)
} }