Add endpoint for health checking the server (ping)
This commit is contained in:
parent
304eb928eb
commit
aebdb733a8
|
@ -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)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue