-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathorder_parser.go
More file actions
54 lines (50 loc) · 1.07 KB
/
Copy pathorder_parser.go
File metadata and controls
54 lines (50 loc) · 1.07 KB
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
package gosql
import "encoding/json"
func (o *OrderRoot) ParseJSONString(str string) error {
var m map[string]interface{}
if err := json.Unmarshal([]byte(str), &m); err != nil {
return err
}
return o.Parse(m)
}
func (o *OrderRoot) Parse(m map[string]interface{}) error {
if m == nil || len(m) == 0 {
return nil
}
for k, v := range m {
if v == nil {
} else if !IsOrderKey(k) {
} else if strs, ok := v.([]interface{}); ok && len(strs) != 0 {
if o.Values == nil {
o.Values = make([]IOrder, 0, len(strs))
}
for _, str := range strs {
value := &OrderValue{}
if err := value.Parse(str); err == nil {
o.Values = append(o.Values, value)
}
}
}
}
return nil
}
func (o *OrderValue) Parse(obj interface{}) error {
if str, ok := obj.(string); !ok {
return ErrTypeString
} else if len(str) == 0 {
return ErrTypeString
} else {
switch str[:1] {
case OrderKeyASC:
o.Key = OrderKeyASC
o.Field = str[1:]
case OrderKeyDESC:
o.Key = OrderKeyDESC
o.Field = str[1:]
default:
o.Key = OrderKeyASC
o.Field = str
}
}
return nil
}