convert return types in go template
This commit is contained in:
parent
2c6429065b
commit
a83446019d
@ -50,6 +50,17 @@ func (g *GoApiGenerator) Generate(apis *api.Api, destFile string) error {
|
||||
}
|
||||
return td, nil
|
||||
},
|
||||
"convtype": func(valDef string, valType api.ValType) (string, error) {
|
||||
td, ok := map[api.ValType]string{
|
||||
api.TInt: fmt.Sprintf("int(%s.(float64))", valDef),
|
||||
api.TString: fmt.Sprintf("%s.(string)", valDef),
|
||||
api.TBool: fmt.Sprintf("%s.(bool)", valDef),
|
||||
}[valType]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("cannot convert type %v for val %s", valType, valDef)
|
||||
}
|
||||
return td, nil
|
||||
},
|
||||
"zerovalue": func(t api.ValType) (string, error) {
|
||||
v, ok := map[api.ValType]string{
|
||||
api.TInt: "0",
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
{{- /*gotype: efprojects.com/kitten-ipc/kitcom.goGenData*/ -}}
|
||||
{{- /*gotype: efprojects.com/kitten-ipc/kitcom/internal/golang.goGenData*/ -}}
|
||||
|
||||
// Code generated by kitcom. DO NOT EDIT.
|
||||
|
||||
@ -27,7 +26,7 @@ func ({{$e.Name | receiver}} *{{$e.Name}}) {{$mtd.Name}}(
|
||||
return {{ range $mtd.Ret }}{{ .Type | zerovalue }}, {{ end }} fmt.Errorf("call to {{ $e.Name }}.{{ $mtd.Name }} failed: %w", err)
|
||||
}
|
||||
_ = results
|
||||
return {{range $idx, $ret := $mtd.Ret}}results[{{$idx}}].({{$ret.Type | typedef}}), {{end}}nil
|
||||
return {{ range $idx, $ret := $mtd.Ret }}{{ convtype ( printf "results[%d]" $idx ) $ret.Type }}, {{ end }}nil
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user