-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
32 lines (29 loc) · 858 Bytes
/
util.go
File metadata and controls
32 lines (29 loc) · 858 Bytes
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
package greq
import (
"fmt"
ge "github.com/og/x/error"
core_ogjson "github.com/og/json/core"
"reflect"
)
func structToMap (structValue interface{}, tag string) map[string][]string {
data := map[string][]string{}
bList, err := core_ogjson.Marshal(structValue, tag) ;ge.Check(err)
headerMap := map[string]interface{}{}
err = core_ogjson.Unmarshal(bList, &headerMap, "header") ; ge.Check(err)
for key, value := range headerMap {
rValue := reflect.ValueOf(value)
switch rValue.Type().Kind() {
case reflect.String:
target := value.(string)
data[key] = append(data[key], target)
case reflect.Slice:
for i:=0;i<rValue.Len();i++ {
itemValue := rValue.Index(i)
data[key] = append(data[key], fmt.Sprintf(`%v`, itemValue.Interface()))
}
default:
data[key] = append(data[key], fmt.Sprintf(`%v`, value))
}
}
return data
}