add user service
This commit is contained in:
29
main.go
29
main.go
@@ -1,38 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"astra-api-gateway/config"
|
||||
"astra-api-gateway/handler"
|
||||
"astra-api-gateway/model"
|
||||
"astra-api-gateway/mw"
|
||||
"astra-api-gateway/services/users"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
func init() {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Print("No .env file found")
|
||||
}
|
||||
e := echo.New()
|
||||
}
|
||||
|
||||
db.AutoMigrate(&model.User{})
|
||||
func main() {
|
||||
e := echo.New()
|
||||
|
||||
// Middleware
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(mw.TokenFromCookies)
|
||||
e.Use(mw.JWTMW)
|
||||
|
||||
var h = &handler.Handler{DB: db}
|
||||
e.Use(mw.JWT_MW)
|
||||
|
||||
// Routes
|
||||
e.GET("/*", checkAuth)
|
||||
e.GET("/auth/login", h.Login)
|
||||
e.GET("/health", h.Health)
|
||||
e.POST("/auth/login", users.Login)
|
||||
e.GET("/health", handler.Health)
|
||||
|
||||
e.Logger.Fatal(e.Start(":8080"))
|
||||
e.Logger.Fatal(e.Start(":" + config.Env.Server.Port))
|
||||
}
|
||||
|
||||
func checkAuth(c echo.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user