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

Method debug

expr/attribute.go:664–744  ·  view source on GitHub ↗
(prefix string, seen map[*AttributeExpr]int, indent int)

Source from the content-addressed store, hash-verified

662// Debug dumps the attribute to STDOUT in a goa developer friendly way.
663func (a *AttributeExpr) Debug(prefix string) { a.debug(prefix, make(map[*AttributeExpr]int), 0) }
664func (a *AttributeExpr) debug(prefix string, seen map[*AttributeExpr]int, indent int) {
665 tab := " "
666 tabs := strings.Repeat(tab, indent)
667 prefix = tabs + prefix
668 if IsObject(a.Type) {
669 // avoid infinite recursion
670 if c, ok := seen[a]; ok && c > 1 {
671 fmt.Printf("%s: ...\n", prefix)
672 return
673 }
674 seen[a]++
675 }
676 n := a.Type.Name()
677 if desc := a.Description; desc != "" {
678 fmt.Printf("%s: %s (%s) <%T>\n", prefix, n, desc, a.Type)
679 } else {
680 fmt.Printf("%s: %s <%T>\n", prefix, n, a.Type)
681 }
682 ut, isUT := a.Type.(UserType)
683 switch {
684 case isUT:
685 ut.Attribute().debug("att", seen, indent+1)
686 tabs = strings.Repeat(tab, indent+1)
687 case IsObject(a.Type):
688 for _, nat := range *AsObject(a.Type) {
689 nat.Attribute.debug("- "+nat.Name, seen, indent+1)
690 }
691 case IsArray(a.Type):
692 AsArray(a.Type).ElemType.debug("elem", seen, indent+1)
693 case IsMap(a.Type):
694 m := AsMap(a.Type)
695 m.KeyType.debug("key", seen, indent+1)
696 m.ElemType.debug("elem", seen, indent+1)
697 case IsUnion(a.Type):
698 for _, nat := range AsUnion(a.Type).Values {
699 nat.Attribute.debug("* "+nat.Name, seen, indent+1)
700 }
701 }
702 if rt, ok := a.Type.(*ResultTypeExpr); ok {
703 fmt.Printf("%s%sviews\n", tabs, tab)
704 for _, v := range rt.Views {
705 nats := *AsObject(v.Type)
706 keys := make([]string, len(nats))
707 for i, n := range nats {
708 keys[i] = n.Name
709 }
710 fmt.Printf("%s%s- %s: %v\n", tabs+tab, tab, v.Name, keys)
711 }
712 }
713 if d := a.DefaultValue; d != nil {
714 fmt.Printf("%s%sdefault\n", tabs, tab)
715 fmt.Printf("%s%s%#v\n", tabs+tab, tab, a.DefaultValue)
716 }
717 if len(a.UserExamples) > 0 {
718 fmt.Printf("%s%sexamples\n", tabs, tab)
719 for _, ex := range a.UserExamples {
720 fmt.Printf("%s%s- %s: %#v\n", tabs+tab, tab, ex.Summary, ex.Value)
721 }

Callers 1

DebugMethod · 0.95

Calls 11

IsObjectFunction · 0.85
AsObjectFunction · 0.85
IsArrayFunction · 0.85
AsArrayFunction · 0.85
IsMapFunction · 0.85
AsMapFunction · 0.85
IsUnionFunction · 0.85
AsUnionFunction · 0.85
NameMethod · 0.65
AttributeMethod · 0.65
DebugMethod · 0.45

Tested by

no test coverage detected