@@ -152,7 +152,7 @@ func parseTemplate(template string, fs *ast.File, w *bufio.Writer) error {
152
152
if b .Tok != token .TYPE {
153
153
break
154
154
}
155
- objname = b .Specs [0 ].(* ast.TypeSpec ).Name .Name
155
+ objname = strings . Title ( b .Specs [0 ].(* ast.TypeSpec ).Name .Name )
156
156
}
157
157
return true
158
158
})
@@ -176,15 +176,16 @@ func parseTemplate(template string, fs *ast.File, w *bufio.Writer) error {
176
176
ntype := fmt .Sprintf ("%s" , field .Type )
177
177
template = strings .Replace (template , "$iType" , ntype , - 1 )
178
178
if predicateGenertor {
179
- cond := ""
179
+ fcond := ""
180
180
switch ntype {
181
181
case "string" :
182
- cond = fmt . Sprintf ( "len(%s) == 0" , field . Names [ 0 ]. Name )
182
+ fcond = "len(%s.%s ) == 0"
183
183
case "bool" :
184
- cond = fmt . Sprintf ( "%s == true" , field . Names [ 0 ]. Name )
184
+ fcond = "%s.%s == true"
185
185
case "int" :
186
- cond = fmt . Sprintf ( "%s == 0" , field . Names [ 0 ]. Name )
186
+ fcond = "%s.%s == 0"
187
187
}
188
+ cond := fmt .Sprintf (fcond , string (strings .ToLower (objname )[0 ]), field .Names [0 ].Name )
188
189
template = strings .Replace (template , "$cond" , cond , - 1 )
189
190
}
190
191
_ , err := w .WriteString (template )
@@ -217,7 +218,7 @@ func copyStructFile(fs *ast.File, w *bufio.Writer) {
217
218
if b .Tok != token .TYPE {
218
219
break
219
220
}
220
- _ , err := fmt .Fprintf (w , "\n type %s struct {\n " , b .Specs [0 ].(* ast.TypeSpec ).Name .Name )
221
+ _ , err := fmt .Fprintf (w , "\n type %s struct {\n " , strings . Title ( b .Specs [0 ].(* ast.TypeSpec ).Name .Name ) )
221
222
if err != nil {
222
223
log .Fatalf ("Failed to write struct : %v" , err )
223
224
}
0 commit comments