Files
astra-api-gateway/main.go
2023-06-23 17:24:52 +03:00

40 lines
749 B
Go

package main
import (
"astra-api-gateway/config"
"astra-api-gateway/handler"
"astra-api-gateway/mw"
"astra-api-gateway/services/users"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"log"
"net/http"
)
func init() {
if err := godotenv.Load(); err != nil {
log.Print("No .env file found")
}
}
func main() {
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(mw.TokenFromCookies)
e.Use(mw.JWT_MW)
// Routes
e.GET("/*", checkAuth)
e.POST("/auth/login", users.Login)
e.GET("/health", handler.Health)
e.Logger.Fatal(e.Start(":" + config.Env.Server.Port))
}
func checkAuth(c echo.Context) error {
return c.HTML(http.StatusOK, c.Request().Header.Get("UserId"))
}