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