Skip to content

Commit

Permalink
fixed: 类型和包的解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Luoxin committed Jan 2, 2025
1 parent 5474d74 commit 3eb0e01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions codegen/pbparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,24 +328,21 @@ func (p *PbRPC) walk() {
}
if idx := strings.LastIndex(text, "."); idx > 0 {
p.requestPackage = text[idx+1:]
} else {
p.requestPackage = text
text = text[:idx]
}
}

if strings.Contains(p.rpc.ReturnsType, ".") {
text := p.rpc.ReturnsType
if idx := strings.LastIndex(text, "."); idx > 0 {
p.responsePackage = text[idx+1:]
p.returnsType = text[idx+1:]
text = text[:idx]
}
if idx := strings.LastIndex(text, "."); idx > 0 {
p.responsePackage = text[idx+1:]
} else {
p.responsePackage = text
text = text[:idx]
}
}

}

func NewPbRPC(rpc *proto.RPC) *PbRPC {
Expand Down
4 changes: 2 additions & 2 deletions codegen/template/client.call.gtpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
func {{ .RPC.RpcName }}(ctx *lrpc.Ctx, req *{{ .RequestType }}) (*{{ .ResponseType }}, error) {
var rsp {{ .ResponseType }}
func {{ .RPC.RpcName }}(ctx *lrpc.Ctx, req *{{ .RequestPackage }}.{{ .RequestType }}) (*{{ .ResponsePackage }}.{{ .ResponseType }}, error) {
var rsp {{ .ResponsePackage }}.{{ .ResponseType }}
return &rsp, lrpc.Call(ctx, &core.ServiceDiscoveryClient{
ServiceName: ServerName,
ServicePath: RpcPath{{ .RPC.RpcName }},
Expand Down

0 comments on commit 3eb0e01

Please sign in to comment.