-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.go
103 lines (79 loc) · 1.96 KB
/
builder.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
102
103
package main
import "strings"
var (
dataBuilders map[string]IDataBuilder
)
type SheetConfig struct {
VarType string
TypeName string
ClassName string
KeyFormat string
KeyInputs []string
KeyParams []string
}
func init() {
dataBuilders = make(map[string]IDataBuilder)
dataBuilders["@PE"] = &PersistDataBuilder{}
dataBuilders["@EX"] = &ExpireDataBuilder{}
dataBuilders["@HA"] = &HashDataBuilder{}
}
type IDataBuilder interface {
Build(msg string, params []string) (config *SheetConfig, err error)
}
type BaseDataBuilder struct {
Builder interface{}
}
// @PE
type PersistDataBuilder struct {
BaseDataBuilder
}
func (p *PersistDataBuilder) Build(typeName string, params []string) (config *SheetConfig,
err error) {
config = &SheetConfig{
VarType: typePersist,
ClassName: params[1],
TypeName: typeName,
KeyFormat: params[2],
}
for i := 3; i < len(params)-1; i += 2 {
config.KeyParams = append(config.KeyParams, params[i])
config.KeyInputs = append(config.KeyInputs, strings.Join(params[i:i+2], " "))
}
return
}
// @EX
type ExpireDataBuilder struct {
BaseDataBuilder
}
func (p *ExpireDataBuilder) Build(typeName string, params []string) (config *SheetConfig,
err error) {
config = &SheetConfig{
VarType: typeExpire,
ClassName: params[1],
TypeName: typeName,
KeyFormat: params[2],
}
for i := 3; i < len(params)-1; i += 2 {
config.KeyParams = append(config.KeyParams, params[i])
config.KeyInputs = append(config.KeyInputs, strings.Join(params[i:i+2], " "))
}
return
}
// @HA
type HashDataBuilder struct {
BaseDataBuilder
}
func (p *HashDataBuilder) Build(typeName string, params []string) (config *SheetConfig,
err error) {
config = &SheetConfig{
VarType: typeHash,
ClassName: params[1],
TypeName: typeName,
KeyFormat: params[2],
}
for i := 3; i < len(params)-1; i += 2 {
config.KeyParams = append(config.KeyParams, params[i])
config.KeyInputs = append(config.KeyInputs, strings.Join(params[i:i+2], " "))
}
return
}