NewDecoder returns a new decoder for the given configuration. Once a decoder has been returned, the same configuration must not be used again.
(config *DecoderConfig)
| 372 | // a decoder has been returned, the same configuration must not be used |
| 373 | // again. |
| 374 | func NewDecoder(config *DecoderConfig) (*Decoder, error) { |
| 375 | val := reflect.ValueOf(config.Result) |
| 376 | if val.Kind() != reflect.Ptr { |
| 377 | return nil, errors.New("result must be a pointer") |
| 378 | } |
| 379 | |
| 380 | val = val.Elem() |
| 381 | if !val.CanAddr() { |
| 382 | return nil, errors.New("result must be addressable (a pointer)") |
| 383 | } |
| 384 | |
| 385 | if config.Metadata != nil { |
| 386 | if config.Metadata.Keys == nil { |
| 387 | config.Metadata.Keys = make([]string, 0) |
| 388 | } |
| 389 | |
| 390 | if config.Metadata.Unused == nil { |
| 391 | config.Metadata.Unused = make([]string, 0) |
| 392 | } |
| 393 | |
| 394 | if config.Metadata.Unset == nil { |
| 395 | config.Metadata.Unset = make([]string, 0) |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if config.TagName == "" { |
| 400 | config.TagName = "mapstructure" |
| 401 | } |
| 402 | |
| 403 | if config.MatchName == nil { |
| 404 | config.MatchName = strings.EqualFold |
| 405 | } |
| 406 | |
| 407 | result := &Decoder{ |
| 408 | config: config, |
| 409 | } |
| 410 | |
| 411 | return result, nil |
| 412 | } |
| 413 | |
| 414 | // Decode decodes the given raw interface to the target pointer specified |
| 415 | // by the configuration. |
no outgoing calls
searching dependent graphs…