-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.go
79 lines (70 loc) · 1.93 KB
/
model.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package iam
import (
"encoding/json"
"errors"
"github.com/codingXiang/cxgateway/v3/util/response"
"github.com/gin-gonic/gin"
"time"
)
type Object struct {
Type string `json:"type"`
Subject string `json:"subject"`
Object string `json:"object"`
Action string `json:"action"`
}
type Response struct {
User *User `json:"user"`
}
func Resp2User(in []byte) (resp response.Response, err error) {
err = json.Unmarshal(in, &resp)
return
}
type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
RogAccount string `json:"rogaccount"`
Email string `json:"email"`
EmailVerifiedAt time.Time `json:"email_verified_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Roles []*Role `json:"roles"`
Permissions []*Permission `json:"permissions"`
}
func GetUser(c *gin.Context) (*User, error) {
in, exist := c.Get(UserInfo)
if !exist {
return nil, errors.New("user info not exist in context")
}
b, err := json.Marshal(in)
if err != nil {
return nil, err
}
var user = new(User)
err = json.Unmarshal(b, &user)
if err != nil {
return nil, err
}
return user, nil
}
type Role struct {
ID int64 `json:"id"`
Name string `json:"name"`
GuardName string `json:"guardName"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Pivot *Pivot `json:"pivot"`
}
type Pivot struct {
ModelID int64 `json:"model_id,omitempty"`
RoleID int64 `json:"role_id,omitempty"`
ModelType string `json:"model_type,omitempty"`
PermissionID int64 `json:"permission_id,omitempty"`
}
type Permission struct {
ID int64 `json:"id"`
Name string `json:"name"`
GuardName string `json:"guardName"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Pivot *Pivot `json:"pivot"`
}