-
Notifications
You must be signed in to change notification settings - Fork 1
/
complaint_types.go
76 lines (64 loc) · 1.58 KB
/
complaint_types.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
package customer
import (
"context"
"github.com/webx-top/echo"
"github.com/admpub/webx/application/dbschema"
)
var (
ComplaintTypes = echo.NewKVData()
ComplaintTargets = echo.NewKVData()
)
type ComplaintFunc func(*dbschema.OfficialCommonComplaint) error
func init() {
ComplaintTypeAdd(`illegal`, `非法内容`, nil)
ComplaintTypeAdd(`infringing`, `侵权内容`, nil)
ComplaintTypeAdd(`other`, `其它`, nil)
}
func ComplaintTypeAdd(key, name string, fn ComplaintFunc) {
item := &echo.KV{
K: key,
V: name,
}
if fn != nil {
item.SetFn(func(context.Context) interface{} {
return fn
})
}
ComplaintTypes.AddItem(item)
}
func ExecComplaintTypeFunc(key string, mdl *dbschema.OfficialCommonComplaint) error {
item := ComplaintTypes.GetItem(key)
if item == nil || item.Fn() == nil {
return nil
}
return item.Fn()(mdl.Context()).(ComplaintFunc)(mdl)
}
func ComplaintTypeList() []*echo.KV {
return ComplaintTypes.Slice()
}
func ComplaintTargetAdd(key, name string, fn ComplaintFunc, urlFormat func(*dbschema.OfficialCommonComplaint) string) {
item := &echo.KV{
K: key,
V: name,
}
if fn != nil {
item.SetFn(func(context.Context) interface{} {
return fn
})
}
extraX := echo.H{
`urlFormat`: urlFormat,
}
item.X = extraX
ComplaintTargets.AddItem(item)
}
func ExecComplaintTargetFunc(key string, mdl *dbschema.OfficialCommonComplaint) error {
item := ComplaintTargets.GetItem(key)
if item == nil || item.Fn() == nil {
return nil
}
return item.Fn()(mdl.Context()).(ComplaintFunc)(mdl)
}
func ComplaintTargetList() []*echo.KV {
return ComplaintTargets.Slice()
}