-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
get_user_perm_code_logic.go
43 lines (36 loc) · 1.02 KB
/
get_user_perm_code_logic.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 user
import (
"context"
"net/http"
"strings"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserPermCodeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserPermCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserPermCodeLogic {
return &GetUserPermCodeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetUserPermCodeLogic) GetUserPermCode() (resp *types.PermCodeResp, err error) {
roleId := l.ctx.Value("roleId").(string)
if roleId == "" {
return nil, &errorx.ApiError{
Code: http.StatusUnauthorized,
Msg: "login.requireLogin",
}
}
return &types.PermCodeResp{
BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.ctx, i18n.Success)},
Data: strings.Split(roleId, ","),
}, nil
}