MCPcopy Create free account
hub / github.com/pace/bricks / invoke

Method invoke

http/jsonapi/generator/generate_helper.go:42–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func (g *typeGenerator) invoke() error { // nolint: gocyclo
43 if g.schema.Type.Is("string") {
44 switch g.schema.Format {
45 case "byte": // TODO: needs to be base64 encoded/decoded
46 g.stmt.Index().Byte()
47 case "binary":
48 g.stmt.Index().Byte()
49 case "date-time":
50 if jsonapi, ok := g.tags["jsonapi"]; ok { // add hint for jsonapi that time is in iso8601 format
51 g.tags["jsonapi"] = jsonapi + ",iso8601"
52 } else {
53 addValidator(g.tags, "iso8601")
54 }
55
56 if g.isParam {
57 g.stmt.Qual("time", "Time")
58 } else {
59 g.stmt.Op("*").Qual("time", "Time") // time.Time can not be nil, so a pointer is needed for omitempty to work
60 }
61 case "date":
62 addValidator(g.tags, "time(2006-01-02)")
63 if g.isParam {
64 g.stmt.Qual("time", "Time")
65 } else {
66 g.stmt.Op("*").Qual("time", "Time") // time.Time can not be nil, so a pointer is needed for omitempty to work
67 }
68 case "uuid":
69 addValidator(g.tags, "uuid")
70 if g.schema.Nullable {
71 g.stmt.Op("*").String()
72 } else {
73 g.stmt.String()
74 }
75 case "decimal":
76 addValidator(g.tags, "matches(^(\\d*\\.)?\\d+$)")
77 if g.isParam {
78 g.stmt.Qual(pkgDecimal, "Decimal")
79 } else {
80 g.stmt.Op("*").Qual(pkgDecimal, "Decimal")
81 }
82 default:
83 if g.schema.Nullable {
84 g.stmt.Op("*").String()
85 } else {
86 g.stmt.String()
87 }
88 }
89 } else if g.schema.Type.Is("integer") {
90 removeOmitempty(g.tags)
91 switch g.schema.Format {
92 case "int32":
93 if g.schema.Nullable {
94 g.stmt.Op("*").Int32()
95 } else {
96 g.stmt.Int32()
97 }
98 default:
99 if g.schema.Nullable {

Callers 3

buildTypeMethod · 0.80
generateIDFieldMethod · 0.80
generateRequestStructMethod · 0.80

Calls 6

addValidatorFunction · 0.85
removeOmitemptyFunction · 0.85
hasValidatorFunction · 0.85
goTypeMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected