forked from bluele/gforms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
values.go
60 lines (52 loc) · 843 Bytes
/
values.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
package gforms
import (
"reflect"
)
type Data map[string]*V
type V struct {
RawStr string
RawValue interface{}
// not ptr-value
Value interface{}
IsNil bool
// value's kind
Kind reflect.Kind
}
func newV(str string, value interface{}, kind reflect.Kind) *V {
v := new(V)
v.Kind = kind
v.IsNil = true
v.RawStr = str
v.RawValue = value
return v
}
func nilV(str string) *V {
v := new(V)
v.IsNil = true
v.RawStr = str
return v
}
func (self *V) rawValueAsString() *string {
v, ok := self.RawValue.([]string)
if ok {
return &v[0]
} else {
return nil
}
}
func (self *V) rawValueAsBool() bool {
v, ok := self.RawValue.(bool)
if ok {
return v
} else {
return false
}
}
func (self *V) rawValueAsStringArray() []string {
v, ok := self.RawValue.([]string)
if ok {
return v
} else {
return []string{}
}
}