This commit is contained in:
2023-03-01 23:53:06 +08:00
commit 1aaefefac1
20 changed files with 1295 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
package routers
import (
"frank/gin-login-register/controllers"
"github.com/gin-gonic/gin"
)
func InitCommonRouter(r *gin.RouterGroup) {
r.GET("/hello", controllers.SayHello)
}
+26
View File
@@ -0,0 +1,26 @@
package routers
import (
"context"
"frank/gin-login-register/controllers"
"frank/gin-login-register/middles"
"frank/gin-login-register/services"
"github.com/gin-gonic/gin"
)
func InitUserRouter(ctx context.Context, userService services.UserService, router *gin.RouterGroup) {
controllersImpl := controllers.NewUserControllersImpl(ctx, userService)
router.POST("/register", controllersImpl.Register)
authMiddleware, err := middles.InitAuthMiddlewares(controllersImpl)
if err != nil {
panic(err)
}
router.POST("/login", authMiddleware.LoginHandler)
router.POST("/refresh_token", authMiddleware.RefreshHandler)
{
auth := router.Use(authMiddleware.MiddlewareFunc())
auth.POST("/logout", authMiddleware.LogoutHandler)
auth.GET("/list", controllersImpl.UserList)
}
}