- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/xinliangnote/go-gin-api/configs"
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
|
|
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
|
)
|
|
|
|
type logoutResponse struct {
|
|
Username string `json:"username"` // 用户账号
|
|
}
|
|
|
|
// Logout 管理员登出
|
|
// @Summary 管理员登出
|
|
// @Description 管理员登出
|
|
// @Tags API.admin
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Success 200 {object} logoutResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/admin/logout [post]
|
|
// @Security LoginToken
|
|
func (h *handler) Logout() core.HandlerFunc {
|
|
return func(c core.Context) {
|
|
res := new(logoutResponse)
|
|
res.Username = c.SessionUserInfo().UserName
|
|
|
|
if !h.cache.Del(configs.RedisKeyPrefixLoginUser+c.GetHeader(configs.HeaderLoginToken), redis.WithTrace(c.Trace())) {
|
|
c.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.AdminLogOutError,
|
|
code.Text(code.AdminLogOutError)).WithError(errors.New("cache del err")),
|
|
)
|
|
return
|
|
}
|
|
|
|
c.Payload(res)
|
|
}
|
|
}
|