Initial commit

This commit is contained in:
kandrusyak
2023-06-23 02:18:00 +03:00
commit 688ae61bc6
12 changed files with 297 additions and 0 deletions

40
main.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"astra-api-gateway/handler"
"astra-api-gateway/model"
"astra-api-gateway/mw"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"net/http"
)
func main() {
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
e := echo.New()
db.AutoMigrate(&model.User{})
// Middleware
e.Use(middleware.Logger())
e.Use(mw.TokenFromCookies)
e.Use(mw.JWTMW)
var h = &handler.Handler{DB: db}
// Routes
e.GET("/*", checkAuth)
e.GET("/auth/login", h.Login)
e.GET("/health", h.Health)
e.Logger.Fatal(e.Start(":8080"))
}
func checkAuth(c echo.Context) error {
return c.HTML(http.StatusOK, c.Request().Header.Get("UserId"))
}