Skip to content

Commit 881f883

Browse files
author
mayank
committed
Fixing predicate generation
Signed-off-by: mayank <mayank.patel@mayadata.io>
1 parent f48934b commit 881f883

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func parseTemplate(template string, fs *ast.File, w *bufio.Writer) error {
152152
if b.Tok != token.TYPE {
153153
break
154154
}
155-
objname = b.Specs[0].(*ast.TypeSpec).Name.Name
155+
objname = strings.Title(b.Specs[0].(*ast.TypeSpec).Name.Name)
156156
}
157157
return true
158158
})
@@ -176,15 +176,16 @@ func parseTemplate(template string, fs *ast.File, w *bufio.Writer) error {
176176
ntype := fmt.Sprintf("%s", field.Type)
177177
template = strings.Replace(template, "$iType", ntype, -1)
178178
if predicateGenertor {
179-
cond := ""
179+
fcond := ""
180180
switch ntype {
181181
case "string":
182-
cond = fmt.Sprintf("len(%s) == 0", field.Names[0].Name)
182+
fcond = "len(%s.%s) == 0"
183183
case "bool":
184-
cond = fmt.Sprintf("%s == true", field.Names[0].Name)
184+
fcond = "%s.%s == true"
185185
case "int":
186-
cond = fmt.Sprintf("%s == 0", field.Names[0].Name)
186+
fcond = "%s.%s == 0"
187187
}
188+
cond := fmt.Sprintf(fcond, string(strings.ToLower(objname)[0]), field.Names[0].Name)
188189
template = strings.Replace(template, "$cond", cond, -1)
189190
}
190191
_, err := w.WriteString(template)
@@ -217,7 +218,7 @@ func copyStructFile(fs *ast.File, w *bufio.Writer) {
217218
if b.Tok != token.TYPE {
218219
break
219220
}
220-
_, err := fmt.Fprintf(w, "\ntype %s struct {\n", b.Specs[0].(*ast.TypeSpec).Name.Name)
221+
_, err := fmt.Fprintf(w, "\ntype %s struct {\n", strings.Title(b.Specs[0].(*ast.TypeSpec).Name.Name))
221222
if err != nil {
222223
log.Fatalf("Failed to write struct : %v", err)
223224
}

template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func ($obj *$newobj) Get$Var() $iType {
2929
var PredicateVarTemplate = `
3030
// IsSet$Var method check if the $Var field of $NewObj object is set.
3131
func Is$VarSet() PredicateFunc {
32-
return func(c *$newobj) bool {
32+
return func($obj *$newobj) bool {
3333
return $cond
3434
}
3535
}

0 commit comments

Comments
 (0)