Skip to content

Commit

Permalink
feat: respond to 200 in HEAD to /ping
Browse files Browse the repository at this point in the history
  • Loading branch information
ySnoopyDogy committed Nov 19, 2023
1 parent 0150be3 commit 083a247
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"log"
"net/http"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -33,6 +34,11 @@ func main() {

database := initializeDatabase()

router.HEAD("/ping", func(c *gin.Context) {
c.Header("Content-Type", "application/json; charset=utf-8")
c.Status(http.StatusOK)
})

router.GET("/ping", func(c *gin.Context) {
returnPing(c, httpStartTime, database)
})
Expand All @@ -41,7 +47,7 @@ func main() {
token := c.GetHeader("Authorization")

if token != os.Getenv("TOKEN") {
c.Status(401)
c.Status(http.StatusUnauthorized)
c.Abort()
return
}
Expand Down Expand Up @@ -123,7 +129,7 @@ func appendVanGOghRoutes(router *gin.Engine, db *database.Database) *gin.Engine

func returnPing(c *gin.Context, startTime time.Time, db *database.Database) {

http := HttpPing{
response := HttpPing{
Uptime: time.Since(startTime).Milliseconds(),
}

Expand All @@ -146,9 +152,9 @@ func returnPing(c *gin.Context, startTime time.Time, db *database.Database) {
}

returnData := PingStruct{
Http: http,
Http: response,
Redis: redisPing,
}

c.JSON(200, returnData)
c.JSON(http.StatusOK, returnData)
}

0 comments on commit 083a247

Please sign in to comment.