MCPcopy Create free account
hub / github.com/goadesign/goa / MakeMap

Method MakeMap

expr/types.go:598–611  ·  view source on GitHub ↗

MakeMap examines the key type from a Map and create a map with builtin type if possible. The idea is to avoid generating map[any]any, which cannot be handled by json.Marshal.

(raw map[any]any)

Source from the content-addressed store, hash-verified

596// if possible. The idea is to avoid generating map[any]any,
597// which cannot be handled by json.Marshal.
598func (m *Map) MakeMap(raw map[any]any) any {
599 ma := reflect.MakeMap(toReflectType(m))
600 keys := make([]any, 0, len(raw))
601 for key := range raw {
602 keys = append(keys, key)
603 }
604 sort.Slice(keys, func(i, j int) bool {
605 return reflect.ValueOf(keys[i]).String() < reflect.ValueOf(keys[j]).String()
606 })
607 for _, key := range keys {
608 ma.SetMapIndex(reflect.ValueOf(key), reflect.ValueOf(raw[key]))
609 }
610 return ma.Interface()
611}
612
613// ToMap converts a MapVal to a map.
614func (m MapVal) ToMap() map[any]any {

Callers 2

ExampleMethod · 0.95
byLengthFunction · 0.80

Calls 2

toReflectTypeFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected