|
- package zhios_tool_utils
-
- import "sort"
-
- func Struct2UrlParams(obj interface{}) string {
- var str = ""
- mapVal := Struct2Map(obj)
- var keys []string
- for key := range mapVal {
- keys = append(keys, key)
- }
- sort.Strings(keys)
- for _, key := range keys {
- str += key + "=" + AnyToString(mapVal[key]) + "&"
- }
- /*t := reflect.TypeOf(origin)
- v := reflect.ValueOf(origin)
-
- for i := 0; i < t.NumField(); i++ {
- tag := strings.ToLower(t.Field(i).Tag.Get("json"))
- if tag != "sign" {
- switch v.Field(i).Kind(){
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- str += tag + "=" + utils.Int64ToStr(v.Field(i).Int()) + "&"
- break
- case reflect.String:
- str += tag + "=" + v.Field(i).String() + "&"
- break
- case reflect.Bool:
- str += tag + "=" + utils.BoolToStr(v.Field(i).Bool()) + "&"
- break
- case reflect.Float32, reflect.Float64:
- str += tag + "=" + utils.Float64ToStr(v.Field(i).Float())
- break
- case reflect.Array, reflect.Struct, reflect.Slice:
- str += ToUrlKeyValue(v.Field(i).Interface())
- default:
- break
- }
- }
- }*/
- return str
- }
|