mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-04-18 19:00:33 +03:00
connect gateway controller
This commit is contained in:
parent
a472e249c2
commit
3c266bd8f6
@ -1,19 +1,17 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
Config "micrach/config"
|
||||
"net/http"
|
||||
"micrach/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Ping(c *gin.Context) {
|
||||
headerKey := c.Request.Header.Get("Authorization")
|
||||
if Config.App.Gateway.ApiKey != headerKey {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
func Ping(c *fiber.Ctx) error {
|
||||
headerKey := c.GetReqHeaders()["Authorization"]
|
||||
if config.App.Gateway.ApiKey != headerKey {
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "Unauthorized"})
|
||||
}
|
||||
c.JSON(200, gin.H{
|
||||
return c.JSON(fiber.Map{
|
||||
"message": "pong",
|
||||
})
|
||||
}
|
||||
|
16
main.go
16
main.go
@ -17,21 +17,12 @@ import (
|
||||
"micrach/config"
|
||||
"micrach/controllers"
|
||||
"micrach/db"
|
||||
"micrach/gateway"
|
||||
"micrach/repositories"
|
||||
"micrach/templates"
|
||||
"micrach/utils"
|
||||
)
|
||||
|
||||
// func main() {
|
||||
// if Config.App.IsRateLimiterEnabled {
|
||||
// router.Use(middleware)
|
||||
// }
|
||||
// if Config.App.Gateway.Url != "" {
|
||||
// router.GET("/api/ping", Gateway.Ping)
|
||||
// Gateway.Connect()
|
||||
// }
|
||||
// }
|
||||
|
||||
func main() {
|
||||
config.Init()
|
||||
db.Init()
|
||||
@ -73,6 +64,11 @@ func main() {
|
||||
app.Post("/:threadID", controllers.UpdateThread)
|
||||
app.Get("/captcha/:captchaID", controllers.GetCaptcha)
|
||||
|
||||
if config.App.Gateway.Url != "" {
|
||||
app.Get("/api/ping", gateway.Ping)
|
||||
gateway.Connect()
|
||||
}
|
||||
|
||||
log.Println("app - online, port -", strconv.Itoa(config.App.Port))
|
||||
log.Println("all systems nominal")
|
||||
err = app.Listen(":" + strconv.Itoa(config.App.Port))
|
||||
|
Loading…
Reference in New Issue
Block a user