mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package admin_handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/xinliangnote/go-gin-api/configs"
|
|
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
|
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
|
)
|
|
|
|
type logoutResponse struct {
|
|
Username string `json:"username"` // 用户账号
|
|
}
|
|
|
|
// Logout 管理员登出
|
|
// @Summary 管理员登出
|
|
// @Description 管理员登出
|
|
// @Tags API.admin
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} logoutResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/admin/logout [post]
|
|
func (h *handler) Logout() core.HandlerFunc {
|
|
return func(c core.Context) {
|
|
res := new(logoutResponse)
|
|
res.Username = c.UserName()
|
|
|
|
if !h.cache.Del(configs.RedisKeyPrefixLoginUser+c.GetHeader(configs.HeaderLoginToken), redis.WithTrace(c.Trace())) {
|
|
c.AbortWithError(errno.NewError(
|
|
http.StatusBadRequest,
|
|
code.AdminLogOutError,
|
|
code.Text(code.AdminLogOutError)).WithErr(errors.New("cache del err")),
|
|
)
|
|
return
|
|
}
|
|
|
|
c.Payload(res)
|
|
}
|
|
}
|