Giter Club home page Giter Club logo

grpcweb-example's Introduction

Go gRPC-Web Example

Circle CI Go Report Card GoDoc

gRPC-Web Gopher by Egon Elbre (@egonelbre)

An example implementation of a GopherJS React client talking to a Go gRPC server using the Improbable gRPC-Web client implementation and proxy through the protoc-gen-gopherjs bindings generator.

Developing

To run the server on https://localhost:10000:

$ go run main.go

Then you'll need to also install some vendored generators:

$ make install

After that, any changes you make to the proto file in ./proto/ or the JS client code in ./client/ should be followed by

$ make regenerate

You may need to generate the client code twice as the first time will run reactGen and immutableGen which might be necessary for the subsequent gopherjs build to work.

grpcweb-example's People

Contributors

johanbrandhorst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpcweb-example's Issues

client gen broken for me...

Hey,

i have a Makefile to run the code in this repo, but it fails on the regen.
The proto runs, but the "go generate ./client/..." fails ....

cd /Users/apple/workspace/go/src/github.com/johanbrandhorst/grpcweb-example && protoc proto/library/book_service.proto --gopherjs_out=plugins=grpc,Mgoogle/protobuf/timestamp.proto=github.com/johanbrandhorst/protobuf/ptypes/timestamp:./client/ --go_out=plugins=grpc:./server/
google/protobuf
cd /Users/apple/workspace/go/src/github.com/johanbrandhorst/grpcweb-example && go generate ./client/...
proto/library/book_service.pb.gopherjs.go:474:11: GrpcWebPackageIsVersion2 not declared by package grpcweb
proto/library/book_service.pb.gopherjs.go:528:9: ServerStream not declared by package grpcweb
proto/library/book_service.pb.gopherjs.go:512:14: invalid operation: c.client (variable of type *github.com/johanbrandhorst/grpcweb-example/vendor/github.com/johanbrandhorst/protobuf/grpcweb.Client) has no field or method NewServerStream
proto/library/book_service.pb.gopherjs.go:532:15: invalid operation: x.stream (variable with invalid type) has no field or method RecvMsg
proto/library/book_service.pb.gopherjs.go:541:9: invalid operation: x.stream (variable with invalid type) has no field or methodContext

Suggested fix:

i think that the vendored "./vendor/myitcv.io/immutable/cmd/immutableGen" has a dependence on the "myitcv.io/gogenerate" and its changed recently and so you need to revendor it.

i hit this a few days ago and he fixed it on his side:
myitcv/immutable#52

BTW what are you using for vendoring ? Just so i can try to fix this as i move forward also and help..

Gomobile and react

I think this same architectural pattern is a really nice way to build mobile and desktop apps.

I have this working on desktop using the OS's native webview. So it works on all app stores. It's using a golang wrapper for c++.
Will push on a branch if you want.

For mobile I think you can use react native because it also has a webview inside it.
The thing that's a bit harder is compiling a golang background service in the phone. It's likely not a requirement for everyone but pretty nice because you can store you data there and your users have offline / cached access etc.

Am raising this aspect to see if there is interest.

Websocket connection fails with TLS error

[grpcweb-example-e8d1556b-1]2018-02-04T10:32:22.149534773Z �[33mWARN�[0m[2018-02-04T10:32:22.149392233Z] Failed to create transport: connection error: desc = "transport: authentication handshake failed: tls: either ServerName or InsecureSkipVerify must be specified in the tls.Config" 
[grpcweb-example-e8d1556b-1]2018-02-04T10:32:22.150669434Z �[37mDEBU�[0m[2018-02-04T10:32:22.150324609Z] Closed connection                            
[grpcweb-example-e8d1556b-1]2018-02-04T10:32:22.150696443Z 2018/02/04 10:32:22 http: TLS handshake error from 172.17.0.1:35418: EOF 

This seems to be happening only for websocket requests. Could be a problem with the proxy itself.

cannot find package "github.com/gorilla/websocket" in any of:

go run main.go
main.go:14:2: cannot find package "github.com/gorilla/websocket" in any of:
/Users/timothee/homebrew/Cellar/go/1.10.2/libexec/src/github.com/gorilla/websocket (from $GOROOT)
/Users/timothee/go/src/github.com/gorilla/websocket (from $GOPATH)

I had to do:

go get github.com/gorilla/websocket
go get github.com/improbable-eng/grpc-web/go/grpcweb
go get github.com/johanbrandhorst/grpcweb-example/client/compiled
go get github.com/lpar/gzipped
go get github.com/sirupsen/logrus

could these instructions be added to readme? are these the correct instructions?

Doesn't build on Go 1.11.1

Hi,

I'm running Go 1.11.1. However, vendored gopherjs doesn't like it:

~/projects/grpcweb/src/github.com/johanbrandhorst/grpcweb-example$ make install
go version
go version go1.11.1 linux/amd64
go install ./vendor/github.com/golang/protobuf/protoc-gen-go \
        ./vendor/github.com/johanbrandhorst/protobuf/protoc-gen-gopherjs \
        ./vendor/myitcv.io/react/cmd/reactGen \
        ./vendor/myitcv.io/immutable/cmd/immutableGen \
        ./vendor/github.com/foobaz/go-zopfli \
        ./vendor/github.com/gopherjs/gopherjs
# github.com/johanbrandhorst/grpcweb-example/vendor/github.com/gopherjs/gopherjs/compiler
vendor/github.com/gopherjs/gopherjs/compiler/compiler.go:20:9: undefined: ___GOPHERJS_REQUIRES_GO_VERSION_1_10___
Makefile:9: recipe for target 'install' failed
make: *** [install] Error 2

(Yep -- to be sure that the correct Go is referenced, I modified the makefile to invoke go version, but that should be the extent of it.)

Add CI tests

Add some CircleCI tests to ensure builds and generation works.

$GOPATH/src github.com/johanbrandhorst/protobuf/proto/gopherjs.proto: File not found

I am running your example code to learn more..
Had this working a few days ago, but today the make regen is failing.

I assume its looking inside the vendor folder ?
any ideas ?


x-MacBook-Pro:grpcweb-example apple$ make
protoc -I. -I$GOPATH/src proto/library/book_service.proto \
    	--gopherjs_out=plugins=grpc,Mgoogle/protobuf/timestamp.proto=github.com/johanbrandhorst/protobuf/ptypes/timestamp:$GOPATH/src \
    	--go_out=plugins=grpc:$GOPATH/src
github.com/johanbrandhorst/protobuf/proto/gopherjs.proto: File not found.
proto/library/book_service.proto: Import "github.com/johanbrandhorst/protobuf/proto/gopherjs.proto" was not found or had errors.
make[1]: *** [regenerate] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.