mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-04-20 03:40:33 +03:00
feat: add ping controller for check by gateway
This commit is contained in:
parent
a942fa9448
commit
184578df07
@ -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
|
18
controllers/gateway_controller.go
Normal file
18
controllers/gateway_controller.go
Normal 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",
|
||||||
|
})
|
||||||
|
}
|
3
main.go
3
main.go
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user