-
Notifications
You must be signed in to change notification settings - Fork 58
/
func_logout.go
executable file
·43 lines (37 loc) · 1.13 KB
/
func_logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package admin
import (
"net/http"
"github.com/ch3nnn/webstack-go/configs"
"github.com/ch3nnn/webstack-go/internal/code"
"github.com/ch3nnn/webstack-go/internal/pkg/core"
"github.com/ch3nnn/webstack-go/internal/pkg/errors"
"github.com/ch3nnn/webstack-go/internal/repository/redis"
)
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)
}
}