Initial commit
This commit is contained in:
40
main.go
Normal file
40
main.go
Normal 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"))
|
||||
}
|
||||
Reference in New Issue
Block a user