|
|
@ -57,24 +57,24 @@ var errJsonConvert = errors.New("json convert error")
|
|
|
|
{{.types}}
|
|
|
|
{{.types}}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
callInterfaceFunctionTemplate = `{{if .hasComment}}{{.comment}}
|
|
|
|
callInterfaceFunctionTemplate = `{{if .hasComment}}{{.comment}}
|
|
|
|
{{end}}{{.method}}(ctx context.Context,in *{{.pbRequest}}) {{if .hasResponse}}(*{{.pbResponse}},{{end}} error{{if .hasResponse}}){{end}}`
|
|
|
|
{{end}}{{.method}}(ctx context.Context,in *{{.pbRequest}}) (*{{.pbResponse}},error)`
|
|
|
|
callFunctionTemplate = `
|
|
|
|
callFunctionTemplate = `
|
|
|
|
{{if .hasComment}}{{.comment}}{{end}}
|
|
|
|
{{if .hasComment}}{{.comment}}{{end}}
|
|
|
|
func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRequest}}) {{if .hasResponse}}(*{{.pbResponse}},{{end}} error{{if .hasResponse}}){{end}} {
|
|
|
|
func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRequest}}) (*{{.pbResponse}}, error) {
|
|
|
|
var request {{.package}}.{{.pbRequest}}
|
|
|
|
var request {{.package}}.{{.pbRequest}}
|
|
|
|
bts, err := jsonx.Marshal(in)
|
|
|
|
bts, err := jsonx.Marshal(in)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return {{if .hasResponse}}nil, {{end}}errJsonConvert
|
|
|
|
return nil, errJsonConvert
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = jsonx.Unmarshal(bts, &request)
|
|
|
|
err = jsonx.Unmarshal(bts, &request)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return {{if .hasResponse}}nil, {{end}}errJsonConvert
|
|
|
|
return nil, errJsonConvert
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client := {{.package}}.New{{.rpcServiceName}}Client(m.cli.Conn())
|
|
|
|
client := {{.package}}.New{{.rpcServiceName}}Client(m.cli.Conn())
|
|
|
|
{{if .hasResponse}}resp, err := {{else}}_, err = {{end}}client.{{.method}}(ctx, &request)
|
|
|
|
resp, err := client.{{.method}}(ctx, &request)
|
|
|
|
{{if .hasResponse}}if err != nil{
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -89,11 +89,7 @@ func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRe
|
|
|
|
return nil, errJsonConvert
|
|
|
|
return nil, errJsonConvert
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &ret, nil{{else}}if err != nil {
|
|
|
|
return &ret, nil
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil{{end}}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -177,10 +173,6 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
|
|
|
|
pkgName := file.Package
|
|
|
|
pkgName := file.Package
|
|
|
|
functions := make([]string, 0)
|
|
|
|
functions := make([]string, 0)
|
|
|
|
for _, method := range service.Funcs {
|
|
|
|
for _, method := range service.Funcs {
|
|
|
|
data, found := file.Strcuts[strings.ToLower(method.OutType)]
|
|
|
|
|
|
|
|
if found {
|
|
|
|
|
|
|
|
found = len(data.Field) > 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var comment string
|
|
|
|
var comment string
|
|
|
|
if len(method.Document) > 0 {
|
|
|
|
if len(method.Document) > 0 {
|
|
|
|
comment = method.Document[0]
|
|
|
|
comment = method.Document[0]
|
|
|
@ -191,7 +183,6 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
|
|
|
|
"package": pkgName,
|
|
|
|
"package": pkgName,
|
|
|
|
"pbRequest": method.InType,
|
|
|
|
"pbRequest": method.InType,
|
|
|
|
"pbResponse": method.OutType,
|
|
|
|
"pbResponse": method.OutType,
|
|
|
|
"hasResponse": found,
|
|
|
|
|
|
|
|
"hasComment": len(method.Document) > 0,
|
|
|
|
"hasComment": len(method.Document) > 0,
|
|
|
|
"comment": comment,
|
|
|
|
"comment": comment,
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -205,14 +196,9 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *defaultRpcGenerator) getInterfaceFuncs(service *parser.RpcService) ([]string, error) {
|
|
|
|
func (g *defaultRpcGenerator) getInterfaceFuncs(service *parser.RpcService) ([]string, error) {
|
|
|
|
file := g.ast
|
|
|
|
|
|
|
|
functions := make([]string, 0)
|
|
|
|
functions := make([]string, 0)
|
|
|
|
|
|
|
|
|
|
|
|
for _, method := range service.Funcs {
|
|
|
|
for _, method := range service.Funcs {
|
|
|
|
data, found := file.Strcuts[strings.ToLower(method.OutType)]
|
|
|
|
|
|
|
|
if found {
|
|
|
|
|
|
|
|
found = len(data.Field) > 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var comment string
|
|
|
|
var comment string
|
|
|
|
if len(method.Document) > 0 {
|
|
|
|
if len(method.Document) > 0 {
|
|
|
|
comment = method.Document[0]
|
|
|
|
comment = method.Document[0]
|
|
|
@ -224,7 +210,6 @@ func (g *defaultRpcGenerator) getInterfaceFuncs(service *parser.RpcService) ([]s
|
|
|
|
"method": method.Name.Title(),
|
|
|
|
"method": method.Name.Title(),
|
|
|
|
"pbRequest": method.InType,
|
|
|
|
"pbRequest": method.InType,
|
|
|
|
"pbResponse": method.OutType,
|
|
|
|
"pbResponse": method.OutType,
|
|
|
|
"hasResponse": found,
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|