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

Function getHandlerStructCodes

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

Source from the content-addressed store, hash-verified

894}
895
896func getHandlerStructCodes(data tmplData, jsonNamedType int) (string, error) {
897 newFields := []tmplField{}
898 for _, field := range data.Fields {
899 if field.DBDriver == DBDriverMongodb { // mongodb
900 if field.Name == "ID" {
901 field.GoType = "string"
902 }
903 if "*"+field.Name == field.GoType {
904 field.GoType = "*model." + field.Name
905 }
906 if strings.Contains(field.GoType, "[]*") {
907 field.GoType = "[]*model." + strings.ReplaceAll(field.GoType, "[]*", "")
908 }
909 }
910 if jsonNamedType == 0 { // snake case
911 field.JSONName = customToSnake(field.ColName)
912 } else {
913 field.JSONName = customToCamel(field.ColName) // camel case (default)
914 }
915 field.GoType = getHandlerGoType(&field)
916 newFields = append(newFields, field)
917 }
918 data.Fields = newFields
919
920 postStructCode, err := tmplExecuteWithFilter(data, handlerCreateStructTmpl)
921 if err != nil {
922 return "", fmt.Errorf("handlerCreateStructTmpl error: %v", err)
923 }
924
925 putStructCode, err := tmplExecuteWithFilter(data, handlerUpdateStructTmpl, columnID)
926 if err != nil {
927 return "", fmt.Errorf("handlerUpdateStructTmpl error: %v", err)
928 }
929
930 getStructCode, err := tmplExecuteWithFilter(data, handlerDetailStructTmpl, columnID, columnCreatedAt, columnUpdatedAt)
931 if err != nil {
932 return "", fmt.Errorf("handlerDetailStructTmpl error: %v", err)
933 }
934
935 return postStructCode + putStructCode + getStructCode, nil
936}
937
938// customized filter fields
939func tmplExecuteWithFilter(data tmplData, tmpl *template.Template, reservedColumns ...string) (string, error) {

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…