(valueKind reflect.Kind, val string, field reflect.Value, formatTag string)
| 419 | } |
| 420 | |
| 421 | func unmarshalInputToField(valueKind reflect.Kind, val string, field reflect.Value, formatTag string) (bool, error) { |
| 422 | if valueKind == reflect.Pointer { |
| 423 | if field.IsNil() { |
| 424 | field.Set(reflect.New(field.Type().Elem())) |
| 425 | } |
| 426 | field = field.Elem() |
| 427 | } |
| 428 | |
| 429 | fieldIValue := field.Addr().Interface() |
| 430 | // Handle time.Time with custom format tag |
| 431 | if formatTag != "" { |
| 432 | if _, isTime := fieldIValue.(*time.Time); isTime { |
| 433 | t, err := time.Parse(formatTag, val) |
| 434 | if err != nil { |
| 435 | return true, err |
| 436 | } |
| 437 | field.Set(reflect.ValueOf(t)) |
| 438 | return true, nil |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | switch unmarshaler := fieldIValue.(type) { |
| 443 | case BindUnmarshaler: |
| 444 | return true, unmarshaler.UnmarshalParam(val) |
| 445 | case encoding.TextUnmarshaler: |
| 446 | return true, unmarshaler.UnmarshalText([]byte(val)) |
| 447 | } |
| 448 | |
| 449 | return false, nil |
| 450 | } |
| 451 | |
| 452 | func setIntField(value string, bitSize int, field reflect.Value) error { |
| 453 | if value == "" { |
no test coverage detected
searching dependent graphs…