gogo / letmegrpc

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with multiple proto files.

tmc opened this issue · comments

The cli doesn't pass multiple proto files if provided and then each generated file contains an htmlstringer definition (among others).

You mean multiple proto files in the same package is a problem, because of conflicting htmlstringer functions?

Correct.

The generated has changed a bit in the mean time.
Lets look at this file for example:
https://github.com/gogo/letmegrpc/blob/master/test/grpc.letmegrpc.go

You can now inject your own htmlstringer instead of setting a global variable.

func Serve(httpAddr, grpcAddr string, stringer func(req, resp interface{}) ([]byte, error), opts ...google_golang_org_grpc.DialOption) {
    conn, err := google_golang_org_grpc.Dial(grpcAddr, opts...)
    if err != nil {
        log.Fatalf("Dial(%q) = %v", grpcAddr, err)
    }
    MyTestClient := NewMyTestClient(conn)
    MyTestServer := NewHTMLMyTestServer(MyTestClient, stringer)
    net_http.HandleFunc("/MyTest/UnaryCall", MyTestServer.UnaryCall)
    net_http.HandleFunc("/MyTest/Downstream", MyTestServer.Downstream)
    net_http.HandleFunc("/MyTest/Upstream", MyTestServer.Upstream)
    net_http.HandleFunc("/MyTest/Bidi", MyTestServer.Bidi)
    if err := net_http.ListenAndServe(httpAddr, nil); err != nil {
        log.Fatal(err)
    }
}

Also you could write a bit more manual code at rather access NewHTMLMyTestServer and inject the stringer for each client.

func NewHTMLMyTestServer(client MyTestClient, stringer func(req, resp interface{}) ([]byte, error)) *htmlMyTest {
    return &htmlMyTest{client, stringer}
}

This stringer is stored in the struct meaning that every client can have its own stringer.

Maybe this solves your problem?

Reopen if it does not solve your problem.