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

Method GetDefault

expr/attribute.go:559–570  ·  view source on GitHub ↗

GetDefault gets the default value for the child attribute with the given name. It returns nil if the child attribute with the given name does not exist or if the child attribute does not have a default value.

(attName string)

Source from the content-addressed store, hash-verified

557// name. It returns nil if the child attribute with the given name does not
558// exist or if the child attribute does not have a default value.
559func (a *AttributeExpr) GetDefault(attName string) any {
560 if o := AsObject(a.Type); o != nil {
561 att := o.Attribute(attName)
562 if att.DefaultValue != nil {
563 return att.DefaultValue
564 }
565 if ut, ok := att.Type.(UserType); ok && !IsObject(ut) {
566 return ut.Attribute().DefaultValue
567 }
568 }
569 return nil
570}
571
572// SetDefault sets the default for the attribute. It also converts HashVal
573// and ArrayVal to map and slice respectively.

Callers 4

IsRequiredNoDefaultMethod · 0.95
HasDefaultValueMethod · 0.95
transformObjectFunction · 0.80
transformObjectFunction · 0.80

Calls 3

AsObjectFunction · 0.85
IsObjectFunction · 0.85
AttributeMethod · 0.65

Tested by

no test coverage detected