Skip to content

Commit

Permalink
OPTIM/MEDIUM: equal: optimize generation of equal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Aug 28, 2023
1 parent 5da134a commit c863440
Show file tree
Hide file tree
Showing 114 changed files with 1,181 additions and 1,163 deletions.
21 changes: 19 additions & 2 deletions cmd/struct_equal_generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ func generateEqualAndDiff(opt generateEqualAndDiffOptions) error {
"HasPrefix": strings.HasPrefix,
"Title": toTitle,
"CamelCase": toCamelCase,
"LowerCase": toLowerCase,
"JSON": toJSON,
}
tmpl, err := template.New("generate.tmpl").Funcs(funcMaps).Parse(tmplEqualAndDiff)
if err != nil {
return err
}
err = tmpl.Execute(opt.File, map[string]interface{}{

data := map[string]interface{}{
"Mode": opt.Mode,
"Name": opt.Name,
"Type": opt.Type,
Expand All @@ -27,7 +29,22 @@ func generateEqualAndDiff(opt generateEqualAndDiffOptions) error {
"IsComplex": opt.IsComplex,
"IsComparable": opt.IsComparable,
"IsPointer": opt.IsPointer,
})
}

functions := map[string]interface{}{
"Functions": []interface{}{
map[string]interface{}{
"Name": "Equal",
"Data": data,
},
map[string]interface{}{
"Name": "Diff",
"Data": data,
},
},
}

err = tmpl.Execute(opt.File, functions)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit c863440

Please sign in to comment.