syz/router/auth/auth.go

51 lines
1.1 KiB
Go

package auth
import (
"git.zhouxhere.com/zhouxhere/syz/store"
"github.com/labstack/echo/v4"
)
type AuthRouter struct {
*echo.Group
store *store.Store
}
func NewAuthRouter(path string, store *store.Store, echoServer *echo.Echo) *AuthRouter {
echoGroup := echoServer.Group(path)
return &AuthRouter{
Group: echoGroup,
store: store,
}
}
func (a *AuthRouter) RegisterRoutes() error {
a.POST("/login", a.login())
a.GET("/logout", a.logout)
return nil
}
// @Summary 用户登录
// @Description 处理用户登录请求
// @Tags 认证
// @Accept json
// @Produce json
// @Success 200 {object} map[string]string "登录成功"
// @Router /login [post]
func (a *AuthRouter) login() echo.HandlerFunc {
return func(c echo.Context) error {
return c.JSON(200, map[string]string{"message": "login"})
}
}
// @Summary 用户登出
// @Description 处理用户登出请求
// @Tags 认证
// @Accept json
// @Produce json
// @Success 200 {object} map[string]string "登出成功"
// @Router /logout [get]
func (a *AuthRouter) logout(c echo.Context) error {
return c.JSON(200, map[string]string{"message": "logout"})
}