context.go
1.0 KB
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
package domain
import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
type Context struct {
// 公司
CompanyId int `json:"companyId"`
// 操作人
OperatorId int `json:"operatorId"`
// 操作人名称
OperatorName string `json:"operatorName"`
// 租户 (个人、企业)
TenantId int `json:"tenantId"`
// 附加数据
data map[string]interface{}
}
func (c *Context) WithValue(key string, value interface{}) *Context {
if c.data == nil {
c.data = make(map[string]interface{})
}
if _, ok := c.data[key]; ok {
return c
}
c.data[key] = value
return c
}
func (c *Context) GetValue(key string) (interface{}, bool) {
if c.data == nil {
return nil, false
}
if v, ok := c.data[key]; ok {
return v, true
}
return nil, false
}
const (
ContextWithLogLevel = "WithLogLevel"
ContextWithLogMsg = "WithLogMsg"
)
func (c *Context) Access() bool {
for _, userId := range constant.WHITE_LIST_USERS {
if userId == c.OperatorId {
return true
}
}
return false
}