Home / Function/ parseToMap() — fiber Function Reference

parseToMap() — fiber Function Reference

Architecture documentation for the parseToMap() function in mapping.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  e3d28b2d_690a_91ab_0f86_f6fe9bc17027["parseToMap()"]
  5a1aea01_8a49_a350_626b_5da5e78187fd["mapping.go"]
  e3d28b2d_690a_91ab_0f86_f6fe9bc17027 -->|defined in| 5a1aea01_8a49_a350_626b_5da5e78187fd
  ed7cfcc6_c354_02e5_2860_6f84d4b42410["parse()"]
  ed7cfcc6_c354_02e5_2860_6f84d4b42410 -->|calls| e3d28b2d_690a_91ab_0f86_f6fe9bc17027
  style e3d28b2d_690a_91ab_0f86_f6fe9bc17027 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binder/mapping.go lines 128–178

func parseToMap(target reflect.Value, data map[string][]string) error {
	if !target.IsValid() {
		return ErrInvalidDestinationValue
	}

	if target.Kind() == reflect.Interface && !target.IsNil() {
		target = target.Elem()
	}

	if target.Kind() != reflect.Map || target.Type().Key().Kind() != reflect.String {
		return nil // nothing to do for non-map destinations
	}

	if target.IsNil() {
		if !target.CanSet() {
			return ErrMapNilDestination
		}
		target.Set(reflect.MakeMap(target.Type()))
	}

	switch target.Type().Elem().Kind() {
	case reflect.Slice:
		newMap, ok := target.Interface().(map[string][]string)
		if !ok {
			return ErrMapNotConvertible
		}

		maps.Copy(newMap, data)
	case reflect.String:
		newMap, ok := target.Interface().(map[string]string)
		if !ok {
			return ErrMapNotConvertible
		}

		for k, v := range data {
			if len(v) == 0 {
				newMap[k] = ""
				continue
			}
			newMap[k] = v[len(v)-1]
		}
	default:
		// Interface element maps (e.g. map[string]any) are left untouched because
		// the binder cannot safely infer element conversions without mutating
		// caller-provided values. These destinations therefore see a successful
		// no-op parse.
		return nil // it's not necessary to check all types
	}

	return nil
}

Domain

Subdomains

Defined In

Called By

Frequently Asked Questions

What does parseToMap() do?
parseToMap() is a function in the fiber codebase, defined in binder/mapping.go.
Where is parseToMap() defined?
parseToMap() is defined in binder/mapping.go at line 128.
What calls parseToMap()?
parseToMap() is called by 1 function(s): parse.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free