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

Function parseAttributeArgs

dsl/attribute.go:394–455  ·  view source on GitHub ↗
(baseAttr *expr.AttributeExpr, args ...any)

Source from the content-addressed store, hash-verified

392}
393
394func parseAttributeArgs(baseAttr *expr.AttributeExpr, args ...any) (expr.DataType, string, func()) {
395 var (
396 dataType expr.DataType
397 description string
398 fn func()
399 ok bool
400 )
401
402 parseDataType := func(expected string, index int) {
403 if name, ok2 := args[index].(string); ok2 {
404 // Lookup type by name
405 if dataType = expr.Root.UserType(name); dataType == nil {
406 eval.InvalidArgError(expected, args[index])
407 }
408 return
409 }
410 if dataType, ok = args[index].(expr.DataType); !ok {
411 eval.InvalidArgError(expected, args[index])
412 }
413 }
414 parseDescription := func(expected string, index int) {
415 if description, ok = args[index].(string); !ok {
416 eval.InvalidArgError(expected, args[index])
417 }
418 }
419 parseDSL := func(index int, success, failure func()) {
420 if fn, ok = args[index].(func()); ok {
421 success()
422 return
423 }
424 failure()
425 }
426
427 success := func() {}
428
429 switch len(args) {
430 case 0:
431 if baseAttr != nil {
432 dataType = baseAttr.Type
433 } else {
434 dataType = expr.String
435 }
436 case 1:
437 success = func() {
438 if baseAttr != nil {
439 dataType = baseAttr.Type
440 }
441 }
442 parseDSL(0, success, func() { parseDataType("type, type name or func()", 0) })
443 case 2:
444 parseDataType("type or type name", 0)
445 parseDSL(1, success, func() { parseDescription("string or func()", 1) })
446 case 3:
447 parseDataType("type or type name", 0)
448 parseDescription("string", 1)
449 parseDSL(2, success, func() { eval.InvalidArgError("func()", args[2]) })
450 default:
451 eval.TooManyArgError()

Callers 2

AttributeFunction · 0.85
ErrorFunction · 0.85

Calls 3

InvalidArgErrorFunction · 0.92
TooManyArgErrorFunction · 0.92
UserTypeMethod · 0.80

Tested by

no test coverage detected