-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.go
73 lines (61 loc) · 1.3 KB
/
config.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
package solr
// CommonProperty is a common property
type CommonProperty struct {
Name string
Value interface{}
}
// ComponentType is a component type
type ComponentType int
// List of component types
const (
RequestHandler ComponentType = iota
SearchComponent
InitParams
QueryResponseWriter
)
func (ct ComponentType) String() string {
return [...]string{
"requesthandler",
"searchcomponent",
"initparams",
"queryresponsewriter",
}[ct]
}
// Component is a component
type Component struct {
// ct is the component type
ct ComponentType
// name is the component name
name string
// class is the component class
class string
// m is the component configurations
m M
}
// NewComponent returns a new Component
func NewComponent(ct ComponentType) *Component {
return &Component{ct: ct}
}
// Name sets the component name
func (c *Component) Name(name string) *Component {
c.name = name
return c
}
// Class sets the component class
func (c *Component) Class(class string) *Component {
c.class = class
return c
}
// Config sets the component config
func (c *Component) Config(m M) *Component {
c.m = m
return c
}
// BuildComponent builds the component config
func (c *Component) BuildComponent() M {
m := M{"name": c.name, "class": c.class}
for k, v := range c.m {
m[k] = v
}
return m
}