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

Function NewMappedAttributeExpr

expr/mapped_attribute.go:33–61  ·  view source on GitHub ↗

NewMappedAttributeExpr instantiates a mapped attribute expression for the given attribute. The type of att must be Object.

(att *AttributeExpr)

Source from the content-addressed store, hash-verified

31// NewMappedAttributeExpr instantiates a mapped attribute expression for the
32// given attribute. The type of att must be Object.
33func NewMappedAttributeExpr(att *AttributeExpr) *MappedAttributeExpr {
34 if att == nil {
35 return NewEmptyMappedAttributeExpr()
36 }
37 if !IsObject(att.Type) {
38 panic("cannot create a mapped attribute with a non object attribute") // bug
39 }
40 var (
41 nameMap = make(map[string]string)
42 reverseMap = make(map[string]string)
43 validation *ValidationExpr
44 )
45 if att.Validation != nil {
46 validation = att.Validation.Dup()
47 } else if ut, ok := att.Type.(UserType); ok {
48 if val := ut.Attribute().Validation; val != nil {
49 validation = val.Dup()
50 }
51 }
52 attr := DupAtt(att)
53 attr.Validation = validation
54 ma := &MappedAttributeExpr{
55 AttributeExpr: attr,
56 nameMap: nameMap,
57 reverseMap: reverseMap,
58 }
59 ma.Remap()
60 return ma
61}
62
63// Remap recomputes the name mappings from the inner attribute. Use this if
64// the underlying attribute is modified after the mapped attribute has been

Callers 14

goTypeDefFunction · 0.92
walkMatchesFunction · 0.92
MetadataFunction · 0.92
TrailersFunction · 0.92
HeadersFunction · 0.92
walkMatchesFunction · 0.92
compatibleFunction · 0.92
DupMethod · 0.85
PathParamsMethod · 0.85
QueryParamsMethod · 0.85
PrepareMethod · 0.85
httpRequestBodyFunction · 0.85

Calls 6

RemapMethod · 0.95
IsObjectFunction · 0.85
DupAttFunction · 0.85
DupMethod · 0.65
AttributeMethod · 0.65

Tested by

no test coverage detected