-
Notifications
You must be signed in to change notification settings - Fork 53
/
binder_col_name.go
101 lines (92 loc) · 2.92 KB
/
binder_col_name.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package binders
import (
"github.com/crawlab-team/crawlab-core/errors"
"github.com/crawlab-team/crawlab-core/interfaces"
)
func NewColNameBinder(id interfaces.ModelId) (b *ColNameBinder) {
return &ColNameBinder{id: id}
}
type ColNameBinder struct {
id interfaces.ModelId
}
func (b *ColNameBinder) Bind() (res interface{}, err error) {
switch b.id {
// system models
case interfaces.ModelIdArtifact:
return interfaces.ModelColNameArtifact, nil
case interfaces.ModelIdTag:
return interfaces.ModelColNameTag, nil
// operation models
case interfaces.ModelIdNode:
return interfaces.ModelColNameNode, nil
case interfaces.ModelIdProject:
return interfaces.ModelColNameProject, nil
case interfaces.ModelIdSpider:
return interfaces.ModelColNameSpider, nil
case interfaces.ModelIdTask:
return interfaces.ModelColNameTask, nil
case interfaces.ModelIdJob:
return interfaces.ModelColNameJob, nil
case interfaces.ModelIdSchedule:
return interfaces.ModelColNameSchedule, nil
case interfaces.ModelIdUser:
return interfaces.ModelColNameUser, nil
case interfaces.ModelIdSetting:
return interfaces.ModelColNameSetting, nil
case interfaces.ModelIdToken:
return interfaces.ModelColNameToken, nil
case interfaces.ModelIdVariable:
return interfaces.ModelColNameVariable, nil
case interfaces.ModelIdTaskQueue:
return interfaces.ModelColNameTaskQueue, nil
case interfaces.ModelIdTaskStat:
return interfaces.ModelColNameTaskStat, nil
case interfaces.ModelIdPlugin:
return interfaces.ModelColNamePlugin, nil
case interfaces.ModelIdSpiderStat:
return interfaces.ModelColNameSpiderStat, nil
case interfaces.ModelIdDataSource:
return interfaces.ModelColNameDataSource, nil
case interfaces.ModelIdDataCollection:
return interfaces.ModelColNameDataCollection, nil
case interfaces.ModelIdPassword:
return interfaces.ModelColNamePasswords, nil
case interfaces.ModelIdExtraValue:
return interfaces.ModelColNameExtraValues, nil
case interfaces.ModelIdPluginStatus:
return interfaces.ModelColNamePluginStatus, nil
case interfaces.ModelIdGit:
return interfaces.ModelColNameGit, nil
case interfaces.ModelIdRole:
return interfaces.ModelColNameRole, nil
case interfaces.ModelIdUserRole:
return interfaces.ModelColNameUserRole, nil
case interfaces.ModelIdPermission:
return interfaces.ModelColNamePermission, nil
case interfaces.ModelIdRolePermission:
return interfaces.ModelColNameRolePermission, nil
case interfaces.ModelIdEnvironment:
return interfaces.ModelColNameEnvironment, nil
// invalid
default:
return res, errors.ErrorModelNotImplemented
}
}
func (b *ColNameBinder) MustBind() (res interface{}) {
res, err := b.Bind()
if err != nil {
panic(err)
}
return res
}
func (b *ColNameBinder) BindString() (res string, err error) {
res_, err := b.Bind()
if err != nil {
return "", err
}
res = res_.(string)
return res, nil
}
func (b *ColNameBinder) MustBindString() (res string) {
return b.MustBind().(string)
}