gogo / letmegrpc

[maintainer wanted] generates a web form gui from a grpc specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call a HTTP server (which uses grpcServer.ServeHTTP through a ServeMux)

tgulacsi opened this issue · comments

That would be very nice, to be able to call one of several grpc servers listening on the same HTTPS port, but under different paths. grpc.Server.ServeHTTP allows us to create such a server, but I don't know yet how to call it with letmegrpc.
I need to use grpc.Invoke(..., "/prefixpath/package.service/method", ...)
(instead of "/package/service.method").

I don't see an easy solution, as all the client code is generated, with constants as paths.

There is a new NewHandler function that calls all public functions

func NewHandler(grpcAddr string, stringer func(req, resp interface{}) ([]byte, error), opts ...google_golang_org_grpc.DialOption) (net_http.Handler, error) {
    conn, err := google_golang_org_grpc.Dial(grpcAddr, opts...)
    if err != nil {
        return nil, err
    }
    mux := net_http.NewServeMux()
    MyTestClient := NewMyTestClient(conn)
    MyTestServer := NewHTMLMyTestServer(MyTestClient, stringer)
    mux.HandleFunc("/MyTest/UnaryCall", MyTestServer.UnaryCall)
    mux.HandleFunc("/MyTest/Downstream", MyTestServer.Downstream)
    mux.HandleFunc("/MyTest/Upstream", MyTestServer.Upstream)
    mux.HandleFunc("/MyTest/Bidi", MyTestServer.Bidi)
    return mux, nil
}

So you can hook these up in any way you want.

But that calls MyClient.UnaryCall, which is Generated to call "/my
test.MyTest/UnaryCall".
This seems to me a feature request against protoc-gen-go, don't you think?
I'm asking first here 'cause you answer promptly and kindly.

Walter Schulze notifications@github.com ezt írta (időpont: 2016. szept.
24., Szo 11:49):

There is a new NewHandler function that calls all public functions

func NewHandler(grpcAddr string, stringer func(req, resp interface{}) ([]byte, error), opts ...google_golang_org_grpc.DialOption) (net_http.Handler, error) {
conn, err := google_golang_org_grpc.Dial(grpcAddr, opts...)
if err != nil {
return nil, err
}
mux := net_http.NewServeMux()
MyTestClient := NewMyTestClient(conn)
MyTestServer := NewHTMLMyTestServer(MyTestClient, stringer)
mux.HandleFunc("/MyTest/UnaryCall", MyTestServer.UnaryCall)
mux.HandleFunc("/MyTest/Downstream", MyTestServer.Downstream)
mux.HandleFunc("/MyTest/Upstream", MyTestServer.Upstream)
mux.HandleFunc("/MyTest/Bidi", MyTestServer.Bidi)
return mux, nil
}

So you can hook these up in any way you want.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#27 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAPoSri1Ho-kLgTZKezlQWGatz5aIgDsks5qtPI2gaJpZM4KFmme
.

I am not quite understanding what you mean.

What code here is generated by protoc-gen-go?

I'm generating code with protoc-gen-gofast, grpc plugin;
then

  • server:
const prefix = "/dealer/"

mux := http.NewServeMux()
grpcServer := grpc.NewServer()
myServer.RegisterDbDealerServer(grpcServer, db_dealer.NewServer(nil))
mux.Handle(prefix, http.StripPrefix(prefix, grpcServer)
http.ListenAndServeTLS(":8081", "server.crt", "server.key", mux)
  • client:
grpc.Invoke(ctx, prefix+method, args, reply, cc)

where `method = "db_dealer.DbDealer/Login".

This works, I've tried it. Now the question is: can this prefix incorporated in protoc-gen-gogo and/or letmegrpc?

Ooops!
Now I've found out that I do use the code generated by protoc-gen-gofast, without modification!
And I use a WithUnaryInterceptor DialOption and in that I call the invoker with prefix+method as the method name - so after all maybe you're right, and nothing needs to be changed, I only need my own call of tmpprotos.Serve with this special DialOption!

Ok so this issue can be closed?

Think so. Thank you for your patience, to be my rubber duck debugger!

Walter Schulze notifications@github.com ezt írta (időpont: 2016. szept.
24., Szo 17:19):

Ok so this issue can be closed?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#27 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAPoSnVF7URGJzvOAVVeWHqzaV0dfasBks5qtT96gaJpZM4KFmme
.