MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / getCommonHandlerStructCodes

Function getCommonHandlerStructCodes

pkg/sql2code/parser/commonParser.go:172–201  ·  view source on GitHub ↗
(data tmplData, jsonNamedType int)

Source from the content-addressed store, hash-verified

170}
171
172func getCommonHandlerStructCodes(data tmplData, jsonNamedType int) (string, error) {
173 newFields := []tmplField{}
174 for _, field := range data.Fields {
175 if jsonNamedType == 0 { // snake case
176 field.JSONName = customToSnake(field.ColName)
177 } else {
178 field.JSONName = customToCamel(field.ColName) // camel case (default)
179 }
180 field.GoType = getHandlerGoType(&field)
181 newFields = append(newFields, field)
182 }
183 data.Fields = newFields
184
185 postStructCode, err := tmplExecuteWithFilter(data, handlerCreateStructCommonTmpl)
186 if err != nil {
187 return "", fmt.Errorf("handlerCreateStructTmpl error: %v", err)
188 }
189
190 putStructCode, err := tmplExecuteWithFilter(data, handlerUpdateStructCommonTmpl, columnID)
191 if err != nil {
192 return "", fmt.Errorf("handlerUpdateStructTmpl error: %v", err)
193 }
194
195 getStructCode, err := tmplExecuteWithFilter(data, handlerDetailStructCommonTmpl, columnID, columnCreatedAt, columnUpdatedAt)
196 if err != nil {
197 return "", fmt.Errorf("handlerDetailStructTmpl error: %v", err)
198 }
199
200 return postStructCode + putStructCode + getStructCode, nil
201}
202
203func getCommonServiceStructCode(data tmplData) (string, error) {
204 builder := strings.Builder{}

Callers 1

makeCodeFunction · 0.85

Calls 5

customToSnakeFunction · 0.85
customToCamelFunction · 0.85
getHandlerGoTypeFunction · 0.85
tmplExecuteWithFilterFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected