diff --git a/.env.example b/.env.example index 86c77e9..a466c3f 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,6 @@ IS_RATE_LIMITER_ENABLED=true THREADS_MAX_COUNT=50 POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5 THREAD_BUMP_LIMIT=500 -IS_CAPTCHA_ACTIVE=true \ No newline at end of file +IS_CAPTCHA_ACTIVE=true +GATEWAY_URL=http://localhost:3001 +GATEWAY_API_KEY=example \ No newline at end of file diff --git a/controllers/gateway_controller.go b/controllers/gateway_controller.go new file mode 100644 index 0000000..5d23e1a --- /dev/null +++ b/controllers/gateway_controller.go @@ -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", + }) +} diff --git a/main.go b/main.go index c2ee44f..2871fe0 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,9 @@ func main() { } router.Static("/uploads", "./uploads") router.Static("/static", "./static") + if Config.App.Gateway.Url != "" { + router.GET("/ping", Controllers.Ping) + } router.GET("/", Controllers.GetThreads) router.POST("/", Controllers.CreateThread) router.GET("/:threadID", Controllers.GetThread)