44 lines
827 B
Go
44 lines
827 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.FilterHeaders)
|
|
e.Use(mw.TokenFromCookies)
|
|
e.Use(mw.JWT_MW)
|
|
|
|
// Routes
|
|
e.GET("/*", checkAuth)
|
|
e.GET("/health", handler.Health)
|
|
|
|
// Users
|
|
e.POST("/auth/login", users.Login)
|
|
e.GET("/users/me", users.GetCurrentUser)
|
|
|
|
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"))
|
|
}
|