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

Function attributeName

codegen/service/convert.go:845–893  ·  view source on GitHub ↗

attributeName computes the name of the attribute for the given field name and object that must contain the matching attribute.

(obj *expr.Object, name string)

Source from the content-addressed store, hash-verified

843// attributeName computes the name of the attribute for the given field name and
844// object that must contain the matching attribute.
845func attributeName(obj *expr.Object, name string) (string, string) {
846 if obj == nil {
847 return name, ""
848 }
849 // first look for a "struct:field:external" meta
850 for _, nat := range *obj {
851 if m := nat.Attribute.Meta["struct:field:external"]; len(m) > 0 {
852 if m[0] == name {
853 return nat.Name, name
854 }
855 }
856 }
857 for _, nat := range *obj { // Deprecated syntax. Only present for backward compatibility.
858 if m := nat.Attribute.Meta["struct.field.external"]; len(m) > 0 {
859 if m[0] == name {
860 return nat.Name, name
861 }
862 }
863 }
864 // next look for an exact match
865 for _, nat := range *obj {
866 if nat.Name == name {
867 return name, ""
868 }
869 }
870 // next try to lower case first letter
871 ln := strings.ToLower(name[0:1]) + name[1:]
872 for _, nat := range *obj {
873 if nat.Name == ln {
874 return ln, name
875 }
876 }
877 // next look for a lower camel case without acronym
878 lcn := codegen.CamelCase(name, false, false)
879 for _, nat := range *obj {
880 if nat.Name == lcn {
881 return lcn, name
882 }
883 }
884 // finally look for a snake case representation
885 sn := codegen.SnakeCase(name)
886 for _, nat := range *obj {
887 if nat.Name == sn {
888 return sn, name
889 }
890 }
891 // no match, return field name
892 return name, ""
893}
894
895// isPrimitive is true if the given kind matches a goa primitive type.
896func isPrimitive(t reflect.Type) bool {

Callers 1

buildDesignTypeFunction · 0.85

Calls 2

CamelCaseFunction · 0.92
SnakeCaseFunction · 0.92

Tested by

no test coverage detected