mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-23 17:53:05 +02:00
Support direct generation of grpc method (#2474)
* Support direct generation of grpc method when package and service names of proto files are different. * fix req.Interface() return nil.
This commit is contained in:
parent
62c2981baf
commit
1919048c8f
@ -131,7 +131,8 @@ func (g *micro) generateService(file *generator.FileDescriptor, service *pb.Serv
|
||||
|
||||
origServName := service.GetName()
|
||||
serviceName := strings.ToLower(service.GetName())
|
||||
if pkg := file.GetPackage(); pkg != "" {
|
||||
pkg := file.GetPackage()
|
||||
if pkg != "" {
|
||||
serviceName = pkg
|
||||
}
|
||||
servName := generator.CamelCase(origServName)
|
||||
@ -209,7 +210,7 @@ func (g *micro) generateService(file *generator.FileDescriptor, service *pb.Serv
|
||||
descExpr = fmt.Sprintf("&%s.Streams[%d]", serviceDescVar, streamIndex)
|
||||
streamIndex++
|
||||
}
|
||||
g.generateClientMethod(serviceName, servName, serviceDescVar, method, descExpr)
|
||||
g.generateClientMethod(pkg, serviceName, servName, serviceDescVar, method, descExpr)
|
||||
}
|
||||
|
||||
g.P("// Server API for ", servName, " service")
|
||||
@ -331,8 +332,12 @@ func (g *micro) generateClientSignature(servName string, method *pb.MethodDescri
|
||||
return fmt.Sprintf("%s(ctx %s.Context%s, opts ...%s.CallOption) (%s, error)", methName, contextPkg, reqArg, clientPkg, respName)
|
||||
}
|
||||
|
||||
func (g *micro) generateClientMethod(reqServ, servName, serviceDescVar string, method *pb.MethodDescriptorProto, descExpr string) {
|
||||
func (g *micro) generateClientMethod(pkg, reqServ, servName, serviceDescVar string, method *pb.MethodDescriptorProto, descExpr string) {
|
||||
reqMethod := fmt.Sprintf("%s.%s", servName, method.GetName())
|
||||
useGrpc := g.gen.Param["use_grpc"]
|
||||
if useGrpc != "" {
|
||||
reqMethod = fmt.Sprintf("/%s.%s/%s", pkg, servName, method.GetName())
|
||||
}
|
||||
methName := generator.CamelCase(method.GetName())
|
||||
inType := g.typeName(method.GetInputType())
|
||||
outType := g.typeName(method.GetOutputType())
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/streadway/amqp"
|
||||
"go-micro.dev/v4/broker"
|
||||
"go-micro.dev/v4/cmd"
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
type rbroker struct {
|
||||
@ -267,6 +267,13 @@ func (r *rbroker) Subscribe(topic string, handler broker.Handler, opts ...broker
|
||||
for k, v := range msg.Headers {
|
||||
header[k], _ = v.(string)
|
||||
}
|
||||
|
||||
// Get rid of dependence on 'Micro-Topic'
|
||||
msgTopic := header["Micro-Topic"]
|
||||
if msgTopic == "" {
|
||||
header["Micro-Topic"] = msg.RoutingKey
|
||||
}
|
||||
|
||||
m := &broker.Message{
|
||||
Header: header,
|
||||
Body: msg.Body,
|
||||
|
@ -557,7 +557,7 @@ func (router *router) ProcessMessage(ctx context.Context, msg Message) (err erro
|
||||
}
|
||||
|
||||
// read the body into the handler request value
|
||||
if err = cc.ReadBody(req.Interface()); err != nil {
|
||||
if err = cc.ReadBody(req.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user