feat: add ping controller for check by gateway

This commit is contained in:
Yanislav Igonin 2022-02-10 09:21:44 +02:00
parent a942fa9448
commit 184578df07
3 changed files with 24 additions and 1 deletions

View File

@ -6,3 +6,5 @@ THREADS_MAX_COUNT=50
POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5 POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5
THREAD_BUMP_LIMIT=500 THREAD_BUMP_LIMIT=500
IS_CAPTCHA_ACTIVE=true IS_CAPTCHA_ACTIVE=true
GATEWAY_URL=http://localhost:3001
GATEWAY_API_KEY=example

View File

@ -0,0 +1,18 @@
package controllers
import (
Config "micrach/config"
"github.com/gin-gonic/gin"
)
func Ping(c *gin.Context) {
headerKey := c.Request.Header.Get("Authorization")
if Config.App.Gateway.ApiKey != headerKey {
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
return
}
c.JSON(200, gin.H{
"message": "pong",
})
}

View File

@ -67,6 +67,9 @@ func main() {
} }
router.Static("/uploads", "./uploads") router.Static("/uploads", "./uploads")
router.Static("/static", "./static") router.Static("/static", "./static")
if Config.App.Gateway.Url != "" {
router.GET("/ping", Controllers.Ping)
}
router.GET("/", Controllers.GetThreads) router.GET("/", Controllers.GetThreads)
router.POST("/", Controllers.CreateThread) router.POST("/", Controllers.CreateThread)
router.GET("/:threadID", Controllers.GetThread) router.GET("/:threadID", Controllers.GetThread)