add user service

This commit is contained in:
kandrusyak
2023-06-23 17:24:00 +03:00
parent b3e4b8a5ab
commit eab7ec0c90
12 changed files with 114 additions and 41 deletions

29
main.go
View File

@@ -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 {