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

Function ArrayOf

dsl/user_type.go:141–164  ·  view source on GitHub ↗

ArrayOf creates an array type from its element type. ArrayOf may be used wherever types can. The first argument of ArrayOf is the type of the array elements specified by name or by reference. The second argument of ArrayOf is an optional function that defines validations for the array elements. Ex

(v any, fn ...func())

Source from the content-addressed store, hash-verified

139// CollectionOf if the argument is a result type and ArrayOf if it is a user
140// type.
141func ArrayOf(v any, fn ...func()) *expr.Array {
142 var t expr.DataType
143 var ok bool
144 t, ok = v.(expr.DataType)
145 if !ok {
146 if name, ok := v.(string); ok {
147 t = expr.Root.UserType(name)
148 }
149 }
150 // never return nil to avoid panics, errors are reported after DSL execution
151 if t == nil {
152 eval.ReportError("invalid ArrayOf argument: not a type and not a known user type name")
153 return &expr.Array{ElemType: &expr.AttributeExpr{Type: expr.String}}
154 }
155 if len(fn) > 1 {
156 eval.TooManyArgError()
157 return &expr.Array{ElemType: &expr.AttributeExpr{Type: expr.String}}
158 }
159 at := expr.AttributeExpr{Type: t}
160 if len(fn) == 1 {
161 eval.Execute(fn[0], &at)
162 }
163 return &expr.Array{ElemType: &at}
164}
165
166// ArrayOfRequired creates an array type from its element type where elements
167// cannot be null.

Callers 15

TestGetMetaTypeImportsFunction · 0.92
TestDesignTypeFunction · 0.92
TestCompatibleFunction · 0.92
http_error_test.goFile · 0.85
endpoint_dsls.goFile · 0.85
serverStreamingArrayDSLFunction · 0.85
clientStreamingArrayDSLFunction · 0.85
path_dsls.goFile · 0.85

Calls 4

ReportErrorFunction · 0.92
TooManyArgErrorFunction · 0.92
ExecuteFunction · 0.92
UserTypeMethod · 0.80