-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.go
68 lines (56 loc) · 1.08 KB
/
form.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
package golidera
type Former interface {
GetField(string) Fielder
GetFieldOk(string) (Fielder, bool)
GetFields() map[string]Fielder
}
type Form struct {
fields map[string]Fielder
}
func NewForm() *Form {
return &Form{
fields: make(map[string]Fielder),
}
}
func (this *Form) Field(n string, v string) Fielder {
field, ok := this.fields[n]
if !ok {
this.fields[n] = &Field{name: n, value: v}
} else {
field.Value(v)
}
return this.fields[n]
}
func (this *Form) GetField(f string) Fielder {
field, ok := this.GetFieldOk(f)
if ok {
return field
}
return &Field{name: f}
}
func (this *Form) GetFieldOk(f string) (Fielder, bool) {
field, ok := this.fields[f]
return field, ok
}
func (this *Form) GetFields() map[string]Fielder {
return this.fields
}
type Fielder interface {
GetName() string
GetValue() string
Value(string)
}
type Field struct {
name string
value string
errors []error
}
func (this *Field) GetName() string {
return this.name
}
func (this *Field) GetValue() string {
return this.value
}
func (this *Field) Value(v string) {
this.value = v
}