https://github.com/saranonearth/chair-stack-grpc-rest
Implementation of gRPC and grpc-web with GoLang. Demonstration project for presentation on grpc .🚀🐶
https://github.com/saranonearth/chair-stack-grpc-rest
golang grpc grpc-client grpc-go grpc-web protobuf
Last synced: about 1 month ago
JSON representation
Implementation of gRPC and grpc-web with GoLang. Demonstration project for presentation on grpc .🚀🐶
- Host: GitHub
- URL: https://github.com/saranonearth/chair-stack-grpc-rest
- Owner: saranonearth
- Created: 2020-09-04T13:45:48.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-08T11:24:45.000Z (almost 6 years ago)
- Last Synced: 2025-06-17T06:11:25.742Z (about 1 year ago)
- Topics: golang, grpc, grpc-client, grpc-go, grpc-web, protobuf
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chair-stack-grpc-rest
[](https://i.ibb.co/WDZHJdp/chairstack.png)
This project contains implementation of REST and gRPC for a small application called ChairStack using Go Lang.
##### To compile .proto to .go file
```
protoc services.proto --go_out=plugin=grpc .
```
##### To compile .proto to .js file
```
protoc services.proto --js_out=import_style=commonjs:..\client\proto --grpc-web_out=import_style=commonjs,mode=grpcwebtext:..\client\proto
```
#### gRPC Web Wrapper
```
grpcServer := grpc.Server()
grpcWebServer := grpcweb.WrapServer(grpcServer)
httpServer = &http.Server{
Handler: h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 {
grpcWebServer.ServeHTTP(w, r)
} else {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-User-Agent, X-Grpc-Web")
w.Header().Set("grpc-status", "")
w.Header().Set("grpc-message", "")
if grpcWebServer.IsGrpcWebRequest(r) {
grpcWebServer.ServeHTTP(w, r)
}
}
}), &http2.Server{}),
}
```
More: https://rogchap.com/2019/07/26/in-process-grpc-web-proxy/