func okResp(a *design.ActionDefinition) map[string]interface{} { var ok *design.ResponseDefinition for _, resp := range a.Responses { if resp.Status == 200 { ok = resp break } } if ok == nil { return nil } var mt *design.MediaTypeDefinition var ok2 bool if mt, ok2 = design.Design.MediaTypes[design.CanonicalIdentifier(ok.MediaType)]; !ok2 { return nil } name := codegen.GoTypeRef(mt, mt.AllRequired(), 1, false) var pointer string if strings.HasPrefix(name, "*") { name = name[1:] pointer = "*" } typeref := fmt.Sprintf("%s%s.%s", pointer, TargetPackage, name) if strings.HasPrefix(typeref, "*") { typeref = "&" + typeref[1:] } return map[string]interface{}{ "Name": ok.Name, "GoType": codegen.GoNativeType(mt), "TypeRef": typeref, } }
// cmdFieldType computes the Go type name used to store command flags of the given design type. func cmdFieldType(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } suffix = codegen.GoNativeType(t) return pointer + suffix }
// join is a code generation helper function that generates a function signature built from // concatenating the properties (name type) of the given attribute type (assuming it's an object). func join(att *design.AttributeDefinition) string { if att == nil { return "" } obj := att.Type.ToObject() elems := make([]string, len(obj)) i := 0 for n, a := range obj { elems[i] = fmt.Sprintf("%s %s", n, codegen.GoNativeType(a.Type)) i++ } sort.Strings(elems) return strings.Join(elems, ", ") }
func (g *Generator) okResp(a *design.ActionDefinition) map[string]interface{} { var ok *design.ResponseDefinition for _, resp := range a.Responses { if resp.Status == 200 { ok = resp break } } if ok == nil { return nil } var mt *design.MediaTypeDefinition var ok2 bool if mt, ok2 = design.Design.MediaTypes[design.CanonicalIdentifier(ok.MediaType)]; !ok2 { return nil } view := ok.ViewName if view == "" { view = design.DefaultView } pmt, _, err := mt.Project(view) if err != nil { return nil } var typeref string if pmt.IsError() { typeref = `goa.ErrInternal("not implemented")` } else { name := codegen.GoTypeRef(pmt, pmt.AllRequired(), 1, false) var pointer string if strings.HasPrefix(name, "*") { name = name[1:] pointer = "*" } typeref = fmt.Sprintf("%s%s.%s", pointer, g.Target, name) if strings.HasPrefix(typeref, "*") { typeref = "&" + typeref[1:] } typeref += "{}" } var nameSuffix string if view != "default" { nameSuffix = codegen.Goify(view, true) } return map[string]interface{}{ "Name": ok.Name + nameSuffix, "GoType": codegen.GoNativeType(pmt), "TypeRef": typeref, } }
// cmdFieldTypeString computes the Go type name used to store command flags of the given design type. Complex types are String func cmdFieldTypeString(t design.DataType, point bool) string { var pointer, suffix string if point && !t.IsArray() { pointer = "*" } if t.Kind() == design.UUIDKind || t.Kind() == design.DateTimeKind || t.Kind() == design.AnyKind || t.Kind() == design.NumberKind || t.Kind() == design.BooleanKind { suffix = "string" } else if isArrayOfType(t, design.UUIDKind, design.DateTimeKind, design.AnyKind, design.NumberKind, design.BooleanKind) { suffix = "[]string" } else { suffix = codegen.GoNativeType(t) } return pointer + suffix }
func okResp(a *design.ActionDefinition) map[string]interface{} { var ok *design.ResponseDefinition for _, resp := range a.Responses { if resp.Status == 200 { ok = resp break } } if ok == nil { return nil } var mt *design.MediaTypeDefinition var ok2 bool if mt, ok2 = design.Design.MediaTypes[design.CanonicalIdentifier(ok.MediaType)]; !ok2 { return nil } view := "default" if _, ok := mt.Views["default"]; !ok { for v := range mt.Views { view = v break } } pmt, _, err := mt.Project(view) if err != nil { return nil } name := codegen.GoTypeRef(pmt, pmt.AllRequired(), 1, false) var pointer string if strings.HasPrefix(name, "*") { name = name[1:] pointer = "*" } typeref := fmt.Sprintf("%s%s.%s", pointer, TargetPackage, name) if strings.HasPrefix(typeref, "*") { typeref = "&" + typeref[1:] } var nameSuffix string if view != "default" { nameSuffix = codegen.Goify(view, true) } return map[string]interface{}{ "Name": ok.Name + nameSuffix, "GoType": codegen.GoNativeType(pmt), "TypeRef": typeref, } }
// cmdFieldType computes the Go type name used to store command flags of the given design type. func cmdFieldType(t design.DataType) string { if t.Kind() == design.DateTimeKind || t.Kind() == design.UUIDKind { return "string" } return codegen.GoNativeType(t) }