Skip to content

Commit

Permalink
Anonymous func that checks value of arg type interface for nil
Browse files Browse the repository at this point in the history
  • Loading branch information
vediatoni committed Jun 7, 2022
1 parent 65e6810 commit 9a06da1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,20 @@ func (f *Field) CallArgs() string {
}

for _, arg := range f.Args {
args = append(args, "fc.Args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")")
tmp := "fc.Args[" + strconv.Quote(arg.Name) + "].(" + templates.CurrentImports.LookupType(arg.TypeReference.GO) + ")"

if types.IsInterface(arg.TypeReference.GO) {
tmp = fmt.Sprintf(`
func () interface{} {
if fc.Args["%s"] == nil {
return nil
}
return fc.Args["%s"].(interface{})
}()`, arg.Name, arg.Name,
)
}

args = append(args, tmp)
}

return strings.Join(args, ", ")
Expand Down

0 comments on commit 9a06da1

Please sign in to comment.