Merge pull request #112 from miraclesu/form
Refactor ParseForm
Showing
1 changed file
with
3 additions
and
21 deletions
| ... | @@ -206,37 +206,19 @@ func ParseForm(form url.Values, obj interface{}) error { | ... | @@ -206,37 +206,19 @@ func ParseForm(form url.Values, obj interface{}) error { |
| 206 | return err | 206 | return err |
| 207 | } | 207 | } |
| 208 | fieldV.SetBool(b) | 208 | fieldV.SetBool(b) |
| 209 | case reflect.Int: | 209 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 210 | fallthrough | ||
| 211 | case reflect.Int8: | ||
| 212 | fallthrough | ||
| 213 | case reflect.Int16: | ||
| 214 | fallthrough | ||
| 215 | case reflect.Int32: | ||
| 216 | fallthrough | ||
| 217 | case reflect.Int64: | ||
| 218 | x, err := strconv.ParseInt(value, 10, 64) | 210 | x, err := strconv.ParseInt(value, 10, 64) |
| 219 | if err != nil { | 211 | if err != nil { |
| 220 | return err | 212 | return err |
| 221 | } | 213 | } |
| 222 | fieldV.SetInt(x) | 214 | fieldV.SetInt(x) |
| 223 | case reflect.Uint: | 215 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
| 224 | fallthrough | ||
| 225 | case reflect.Uint8: | ||
| 226 | fallthrough | ||
| 227 | case reflect.Uint16: | ||
| 228 | fallthrough | ||
| 229 | case reflect.Uint32: | ||
| 230 | fallthrough | ||
| 231 | case reflect.Uint64: | ||
| 232 | x, err := strconv.ParseUint(value, 10, 64) | 216 | x, err := strconv.ParseUint(value, 10, 64) |
| 233 | if err != nil { | 217 | if err != nil { |
| 234 | return err | 218 | return err |
| 235 | } | 219 | } |
| 236 | fieldV.SetUint(x) | 220 | fieldV.SetUint(x) |
| 237 | case reflect.Float32: | 221 | case reflect.Float32, reflect.Float64: |
| 238 | fallthrough | ||
| 239 | case reflect.Float64: | ||
| 240 | x, err := strconv.ParseFloat(value, 64) | 222 | x, err := strconv.ParseFloat(value, 64) |
| 241 | if err != nil { | 223 | if err != nil { |
| 242 | return err | 224 | return err | ... | ... |
-
Please register or sign in to post a comment