├── .gitignore ├── docs ├── diagram │ ├── jwt.png │ ├── mtls.png │ ├── tls.png │ ├── oauth2.png │ ├── gateway.png │ ├── ordermgt.png │ ├── productinfo.png │ ├── productinfo.drawio │ ├── jwt.drawio │ ├── oauth2.drawio │ ├── tls.drawio │ ├── mtls.drawio │ ├── gateway.drawio │ └── ordermgt.drawio ├── build_executable.md ├── generate_stub_go.md ├── install_protocol_buffer_compiler.md ├── write_client.md ├── write_server.md └── grpc_gateway.md ├── imgs └── book-cover.jpg ├── ordermgt ├── client │ ├── go.mod │ ├── ecommerce │ │ └── order_management.proto │ ├── name_resolver.go │ └── main.go └── service │ ├── go.mod │ ├── hello_service.go │ ├── ecommerce │ ├── order_management.proto │ └── google │ │ └── protobuf │ │ └── wrappers.proto │ ├── main.go │ └── ordermgt_service.go ├── examples ├── loadbalancing │ ├── go.mod │ └── main.go ├── grpc-gateway │ ├── client │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ ├── server │ │ ├── go.mod │ │ ├── main.go │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── google │ │ │ │ └── api │ │ │ │ └── annotations.proto │ │ └── productinfo_service.go │ ├── reverse-proxy │ │ ├── go.mod │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── google │ │ │ │ └── api │ │ │ │ └── annotations.proto │ │ └── main.go │ └── postman │ │ └── gRPC-Gateway.postman_collection.json └── security │ ├── jwt │ └── client │ │ ├── ecommerce │ │ ├── product_info.proto │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ ├── oauth2 │ ├── client │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ └── server │ │ ├── ecommerce │ │ ├── product_info.proto │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ ├── basic-auth │ ├── client │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ └── server │ │ ├── ecommerce │ │ ├── product_info.proto │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ ├── one-way-tls │ ├── client │ │ ├── ecommerce │ │ │ ├── product_info.proto │ │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ └── server │ │ ├── ecommerce │ │ ├── product_info.proto │ │ └── product_info.pb.go │ │ ├── go.mod │ │ └── main.go │ └── two-way-tls │ ├── client │ ├── ecommerce │ │ └── product_info.proto │ ├── go.mod │ └── main.go │ └── server │ ├── ecommerce │ └── product_info.proto │ ├── go.mod │ └── main.go ├── productinfo ├── client │ ├── ecommerce │ │ ├── product_info.proto │ │ └── product_info.pb.go │ ├── go.mod │ └── productinfo_client.go └── service │ ├── ecommerce │ ├── product_info.proto │ └── product_info.pb.go │ ├── go.mod │ ├── main.go │ ├── productinfo_service.go │ ├── productinfo_test.go │ └── productinfo_test_bufconn.go └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.sum 3 | 4 | .DS_Store 5 | **/bin -------------------------------------------------------------------------------- /docs/diagram/jwt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/jwt.png -------------------------------------------------------------------------------- /docs/diagram/mtls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/mtls.png -------------------------------------------------------------------------------- /docs/diagram/tls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/tls.png -------------------------------------------------------------------------------- /imgs/book-cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/imgs/book-cover.jpg -------------------------------------------------------------------------------- /docs/diagram/oauth2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/oauth2.png -------------------------------------------------------------------------------- /docs/diagram/gateway.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/gateway.png -------------------------------------------------------------------------------- /docs/diagram/ordermgt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/ordermgt.png -------------------------------------------------------------------------------- /docs/diagram/productinfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyichen24/grpc-up-and-running/HEAD/docs/diagram/productinfo.png -------------------------------------------------------------------------------- /ordermgt/client/go.mod: -------------------------------------------------------------------------------- 1 | module ordergmt/client 2 | 3 | require ( 4 | github.com/golang/protobuf v1.3.3 5 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 6 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 7 | golang.org/x/text v0.3.2 // indirect 8 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 9 | google.golang.org/grpc v1.27.0 10 | ) 11 | 12 | go 1.13 13 | -------------------------------------------------------------------------------- /ordermgt/service/go.mod: -------------------------------------------------------------------------------- 1 | module ordergmt/service 2 | 3 | require ( 4 | github.com/golang/protobuf v1.3.3 5 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 6 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 7 | golang.org/x/text v0.3.2 // indirect 8 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 9 | google.golang.org/grpc v1.27.0 10 | ) 11 | 12 | go 1.13 13 | -------------------------------------------------------------------------------- /examples/loadbalancing/go.mod: -------------------------------------------------------------------------------- 1 | module examples/loadbalancing 2 | 3 | require ( 4 | github.com/golang/protobuf v1.3.3 5 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 6 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 7 | golang.org/x/text v0.3.2 // indirect 8 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 9 | google.golang.org/grpc v1.27.0 10 | ) 11 | 12 | go 1.13 13 | -------------------------------------------------------------------------------- /productinfo/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /productinfo/service/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/grpc-gateway/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/jwt/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/oauth2/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/oauth2/server/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/basic-auth/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/basic-auth/server/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/server/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/two-way-tls/client/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /examples/security/two-way-tls/server/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ecommerce; 3 | 4 | service ProductInfo { 5 | rpc addProduct(Product) returns (ProductID); 6 | rpc getProduct(ProductID) returns (Product); 7 | } 8 | 9 | message Product { 10 | string id = 1; 11 | string name = 2; 12 | string description = 3; 13 | float price = 4; 14 | } 15 | 16 | message ProductID { 17 | string value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /productinfo/service/go.mod: -------------------------------------------------------------------------------- 1 | module productinfo/service 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/grpc-gateway/server/go.mod: -------------------------------------------------------------------------------- 1 | module examples/grpc-gateway/server 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible 5 | github.com/golang/protobuf v1.3.5 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /docs/build_executable.md: -------------------------------------------------------------------------------- 1 | ## Build Executable File 2 | - Change directory to the directory of `main.go` and `go.mod`. 3 | - Build Executable Files 4 | - For server 5 | ```bash 6 | go build -i -v -o bin/server 7 | ``` 8 | - For client 9 | ```bash 10 | go build -i -v -o bin/client 11 | ``` 12 | - Run Executable Files 13 | - For server 14 | ```bash 15 | ./bin/server 16 | ``` 17 | - For client 18 | ```bash 19 | ./bin/client 20 | ``` 21 | -------------------------------------------------------------------------------- /ordermgt/service/hello_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | hello_pb "google.golang.org/grpc/examples/helloworld/helloworld" 7 | ) 8 | 9 | type helloServer struct{} 10 | 11 | // SayHello implements helloworld.GreeterServer 12 | func (s *helloServer) SayHello(ctx context.Context, in *hello_pb.HelloRequest) (*hello_pb.HelloReply, error) { 13 | log.Printf("Greeter Service - SayHello RPC") 14 | return &hello_pb.HelloReply{Message: "Hello " + in.Name}, nil 15 | } 16 | -------------------------------------------------------------------------------- /productinfo/client/go.mod: -------------------------------------------------------------------------------- 1 | module productinfo/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible 5 | github.com/golang/protobuf v1.3.3 6 | github.com/google/uuid v1.1.1 // indirect 7 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 8 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 9 | golang.org/x/text v0.3.2 // indirect 10 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 11 | google.golang.org/grpc v1.27.0 12 | ) 13 | 14 | go 1.13 15 | -------------------------------------------------------------------------------- /examples/security/jwt/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/jwt/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/oauth2/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/oauth2/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/oauth2/server/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/oauth2/server 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/basic-auth/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/basic-auth/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/basic-auth/server/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/basic-auth/server 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/one-way-tls/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/server/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/one-way-tls/server 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/two-way-tls/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/two-way-tls/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/security/two-way-tls/server/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/security/two-way-tls/server 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible // indirect 5 | github.com/golang/protobuf v1.3.3 6 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 7 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 8 | golang.org/x/text v0.3.2 // indirect 9 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 10 | google.golang.org/grpc v1.27.0 11 | ) 12 | 13 | go 1.13 14 | -------------------------------------------------------------------------------- /examples/grpc-gateway/reverse-proxy/go.mod: -------------------------------------------------------------------------------- 1 | module examples/grpc-gateway/reverse-proxy 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible 5 | github.com/golang/protobuf v1.3.5 6 | github.com/grpc-ecosystem/grpc-gateway v1.14.3 7 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 8 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 9 | golang.org/x/text v0.3.2 // indirect 10 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b 11 | google.golang.org/grpc v1.27.0 12 | ) 13 | 14 | go 1.13 15 | -------------------------------------------------------------------------------- /examples/grpc-gateway/client/go.mod: -------------------------------------------------------------------------------- 1 | module grpc-up-and-running/examples/grpc-gateway/client 2 | 3 | require ( 4 | github.com/gofrs/uuid v3.2.0+incompatible 5 | github.com/golang/protobuf v1.3.3 6 | github.com/google/uuid v1.1.1 // indirect 7 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect 8 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect 9 | golang.org/x/text v0.3.2 // indirect 10 | google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect 11 | google.golang.org/grpc v1.27.0 12 | ) 13 | 14 | go 1.13 15 | -------------------------------------------------------------------------------- /productinfo/service/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | "google.golang.org/grpc" 8 | pb "productinfo/service/ecommerce" 9 | ) 10 | 11 | const ( 12 | port = ":50051" 13 | ) 14 | 15 | func main() { 16 | lis, err := net.Listen("tcp", port) 17 | if err != nil { 18 | log.Fatalf("failed to listen: %v", err) 19 | } 20 | s := grpc.NewServer() 21 | pb.RegisterProductInfoServer(s, &server{}) 22 | 23 | log.Printf("Starting gRPC listener on port " + port) 24 | if err := s.Serve(lis); err != nil { 25 | log.Fatalf("failed to serve: %v", err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/generate_stub_go.md: -------------------------------------------------------------------------------- 1 | ## Generate Server Stub 2 | - Install protoc (protocol buffer compiler) 3 | - Install the gRPC library 4 | ```bash 5 | go get -u google.golang.org/grpc 6 | ``` 7 | - Install the protoc plug-in for Go 8 | ```bash 9 | go get -u github.com/golang/protobuf/protoc-gen-go 10 | ``` 11 | - Make sure `$GOPATH/bin` in the $PATH 12 | ```bash 13 | PATH=$PATH:$GOPATH/bin 14 | ``` 15 | - Run protoc 16 | ``` 17 | protoc -I --go_out=plugins=grpc: 18 | ``` 19 | -------------------------------------------------------------------------------- /examples/grpc-gateway/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | "google.golang.org/grpc" 8 | pb "examples/grpc-gateway/server/ecommerce" 9 | ) 10 | 11 | const ( 12 | port = ":50051" 13 | ) 14 | 15 | func main() { 16 | lis, err := net.Listen("tcp", port) 17 | if err != nil { 18 | log.Fatalf("failed to listen: %v", err) 19 | } 20 | s := grpc.NewServer() 21 | pb.RegisterProductInfoServer(s, &server{}) 22 | 23 | log.Printf("Starting gRPC server on port " + port) 24 | if err := s.Serve(lis); err != nil { 25 | log.Fatalf("failed to serve: %v", err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/grpc-gateway/server/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/api/annotations.proto"; 4 | 5 | package ecommerce; 6 | 7 | service ProductInfo { 8 | rpc addProduct(Product) returns (ProductID) { 9 | option (google.api.http) = { 10 | post: "/v1/product" 11 | body: "*" 12 | }; 13 | } 14 | rpc getProduct(ProductID) returns (Product){ 15 | option (google.api.http) = { 16 | get:"/v1/product/{value}" 17 | }; 18 | } 19 | } 20 | 21 | message Product { 22 | string id = 1; 23 | string name = 2; 24 | string description = 3; 25 | float price = 4; 26 | } 27 | 28 | message ProductID { 29 | string value = 1; 30 | } 31 | -------------------------------------------------------------------------------- /examples/grpc-gateway/reverse-proxy/ecommerce/product_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/api/annotations.proto"; 4 | 5 | package ecommerce; 6 | 7 | service ProductInfo { 8 | rpc addProduct(Product) returns (ProductID) { 9 | option (google.api.http) = { 10 | post: "/v1/product" 11 | body: "*" 12 | }; 13 | } 14 | rpc getProduct(ProductID) returns (Product){ 15 | option (google.api.http) = { 16 | get:"/v1/product/{value}" 17 | }; 18 | } 19 | } 20 | 21 | message Product { 22 | string id = 1; 23 | string name = 2; 24 | string description = 3; 25 | float price = 4; 26 | } 27 | 28 | message ProductID { 29 | string value = 1; 30 | } 31 | -------------------------------------------------------------------------------- /ordermgt/client/ecommerce/order_management.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/wrappers.proto"; 4 | 5 | package ecommerce; 6 | 7 | service OrderManagement { 8 | rpc addOrder(Order) returns (google.protobuf.StringValue); 9 | rpc getOrder(google.protobuf.StringValue) returns (Order); 10 | rpc searchOrders(google.protobuf.StringValue) returns (stream Order); 11 | rpc updateOrders(stream Order) returns (google.protobuf.StringValue); 12 | rpc processOrders(stream google.protobuf.StringValue) returns (stream CombinedShipment); 13 | } 14 | 15 | message Order { 16 | string id = 1; 17 | repeated string items = 2; 18 | string description = 3; 19 | float price = 4; 20 | string destination = 5; 21 | } 22 | 23 | message CombinedShipment { 24 | string id = 1; 25 | string status = 2; 26 | repeated Order ordersList = 3; 27 | } -------------------------------------------------------------------------------- /ordermgt/service/ecommerce/order_management.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/wrappers.proto"; 4 | 5 | package ecommerce; 6 | 7 | service OrderManagement { 8 | rpc addOrder(Order) returns (google.protobuf.StringValue); 9 | rpc getOrder(google.protobuf.StringValue) returns (Order); 10 | rpc searchOrders(google.protobuf.StringValue) returns (stream Order); 11 | rpc updateOrders(stream Order) returns (google.protobuf.StringValue); 12 | rpc processOrders(stream google.protobuf.StringValue) returns (stream CombinedShipment); 13 | } 14 | 15 | message Order { 16 | string id = 1; 17 | repeated string items = 2; 18 | string description = 3; 19 | float price = 4; 20 | string destination = 5; 21 | } 22 | 23 | message CombinedShipment { 24 | string id = 1; 25 | string status = 2; 26 | repeated Order ordersList = 3; 27 | } -------------------------------------------------------------------------------- /examples/grpc-gateway/reverse-proxy/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "net/http" 7 | 8 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 9 | "google.golang.org/grpc" 10 | 11 | gw "examples/grpc-gateway/reverse-proxy/ecommerce" 12 | ) 13 | 14 | var ( 15 | grpcServerEndpoint = "localhost:50051" 16 | reverseProxyPort = "8081" 17 | ) 18 | 19 | func main() { 20 | ctx := context.Background() 21 | ctx, cancel := context.WithCancel(ctx) 22 | defer cancel() 23 | 24 | mux := runtime.NewServeMux() 25 | opts := []grpc.DialOption{grpc.WithInsecure()} 26 | err := gw.RegisterProductInfoHandlerFromEndpoint(ctx, mux, grpcServerEndpoint, opts) 27 | 28 | if err != nil { 29 | log.Fatalf("Fail to register gRPC gateway server endpoint: %v", err) 30 | } 31 | 32 | log.Printf("Starting gRPC gateway server on port " + reverseProxyPort) 33 | if err := http.ListenAndServe(":" + reverseProxyPort, mux); err != nil { 34 | log.Fatalf("Could not setup HTTP endpoint: %v", err) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "time" 7 | 8 | pb "grpc-up-and-running/examples/security/one-way-tls/client/ecommerce" 9 | "google.golang.org/grpc/credentials" 10 | "google.golang.org/grpc" 11 | ) 12 | 13 | var ( 14 | address = "localhost:50051" 15 | hostname = "localhost" 16 | crtFile = "server.crt" // server public certificate. 17 | ) 18 | 19 | func main() { 20 | creds, err := credentials.NewClientTLSFromFile(crtFile, hostname) 21 | if err != nil { 22 | log.Fatalf("failed to load credentials: %v", err) 23 | } 24 | opts := []grpc.DialOption{ 25 | grpc.WithTransportCredentials(creds), 26 | } 27 | 28 | conn, err := grpc.Dial(address, opts...) 29 | if err != nil { 30 | log.Fatalf("did not connect: %v", err) 31 | } 32 | defer conn.Close() 33 | c := pb.NewProductInfoClient(conn) 34 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 35 | defer cancel() 36 | 37 | // Call remote methods 38 | c.AddProduct(ctx, nil) 39 | c.GetProduct(ctx, nil) 40 | } -------------------------------------------------------------------------------- /examples/grpc-gateway/server/ecommerce/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } -------------------------------------------------------------------------------- /examples/grpc-gateway/reverse-proxy/ecommerce/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } -------------------------------------------------------------------------------- /productinfo/client/productinfo_client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "time" 7 | 8 | "google.golang.org/grpc" 9 | pb "productinfo/client/ecommerce" 10 | ) 11 | 12 | const ( 13 | address = "localhost:50051" 14 | ) 15 | 16 | func main() { 17 | conn, err := grpc.Dial(address, grpc.WithInsecure()) 18 | if err != nil { 19 | log.Fatalf("did not connect: %v", err) 20 | } 21 | defer conn.Close() 22 | c := pb.NewProductInfoClient(conn) 23 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 24 | defer cancel() 25 | 26 | // Create a new product 27 | name := "Apple iPhone 11" 28 | description := `Meet Apple iPhone 11. All-new dual-camera system with Ultra Wide and Night mode.` 29 | price := float32(1000.0) 30 | 31 | // Add a new product 32 | r, err := c.AddProduct(ctx, &pb.Product{Name: name, Description: description, Price: price}) 33 | if err != nil { 34 | log.Fatalf("Could not add product: %v", err) 35 | } 36 | log.Printf("Product ID: %s added successfully", r.Value) 37 | 38 | // Get a product 39 | product, err := c.GetProduct(ctx, &pb.ProductID{Value: r.Value}) 40 | if err != nil { 41 | log.Fatalf("Could not get product: %v", err) 42 | } 43 | log.Printf("Product: ", product.String()) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/security/jwt/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "google.golang.org/grpc/credentials/oauth" 6 | "log" 7 | "time" 8 | 9 | "google.golang.org/grpc" 10 | "google.golang.org/grpc/credentials" 11 | pb "grpc-up-and-running/examples/security/jwt/client/ecommerce" 12 | ) 13 | 14 | var ( 15 | address = "localhost:50051" 16 | hostname = "localhost" 17 | crtFile = "server.crt" // server public certificate. 18 | jwtTokenFile = "token.json" // JWT token file. 19 | ) 20 | 21 | func main() { 22 | jwtCreds, err := oauth.NewJWTAccessFromFile(jwtTokenFile) 23 | 24 | creds, err := credentials.NewClientTLSFromFile(crtFile, hostname) 25 | if err != nil { 26 | log.Fatalf("failed to load credentials: %v", err) 27 | } 28 | 29 | opts := []grpc.DialOption{ 30 | grpc.WithPerRPCCredentials(jwtCreds), 31 | grpc.WithTransportCredentials(creds), 32 | } 33 | 34 | conn, err := grpc.Dial(address, opts...) 35 | if err != nil { 36 | log.Fatalf("did not connect: %v", err) 37 | } 38 | defer conn.Close() 39 | c := pb.NewProductInfoClient(conn) 40 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 41 | defer cancel() 42 | 43 | // Call remote methods 44 | c.AddProduct(ctx, nil) 45 | c.GetProduct(ctx, nil) 46 | } -------------------------------------------------------------------------------- /examples/grpc-gateway/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "time" 7 | 8 | "google.golang.org/grpc" 9 | pb "grpc-up-and-running/examples/grpc-gateway/client/ecommerce" 10 | ) 11 | 12 | const ( 13 | address = "localhost:50051" 14 | ) 15 | 16 | func main() { 17 | conn, err := grpc.Dial(address, grpc.WithInsecure()) 18 | if err != nil { 19 | log.Fatalf("did not connect: %v", err) 20 | } 21 | defer conn.Close() 22 | c := pb.NewProductInfoClient(conn) 23 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 24 | defer cancel() 25 | 26 | // Create a new product 27 | name := "Apple iPhone 11" 28 | description := `Meet Apple iPhone 11. All-new dual-camera system with Ultra Wide and Night mode.` 29 | price := float32(1000.0) 30 | 31 | // Add a new product 32 | r, err := c.AddProduct(ctx, &pb.Product{Name: name, Description: description, Price: price}) 33 | if err != nil { 34 | log.Fatalf("Could not add product: %v", err) 35 | } 36 | log.Printf("Product ID: %s added successfully", r.Value) 37 | 38 | // Get a product 39 | product, err := c.GetProduct(ctx, &pb.ProductID{Value: r.Value}) 40 | if err != nil { 41 | log.Fatalf("Could not get product: %v", err) 42 | } 43 | log.Printf("Product: ", product.String()) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "google.golang.org/grpc" 7 | "google.golang.org/grpc/credentials" 8 | pb "grpc-up-and-running/examples/security/one-way-tls/server/ecommerce" 9 | "log" 10 | "net" 11 | ) 12 | 13 | type server struct {} 14 | 15 | var ( 16 | port = ":50051" 17 | crtFile = "server.crt" // server public certificate. 18 | keyFile = "server.key" // server private key. 19 | ) 20 | 21 | func main() { 22 | cert, err := tls.LoadX509KeyPair(crtFile,keyFile) 23 | if err != nil { 24 | log.Fatalf("failed to load key pair: %s", err) 25 | } 26 | opts := []grpc.ServerOption{ 27 | grpc.Creds(credentials.NewServerTLSFromCert(&cert)), 28 | } 29 | 30 | s := grpc.NewServer(opts...) 31 | pb.RegisterProductInfoServer(s, &server{}) 32 | 33 | lis, err := net.Listen("tcp", port) 34 | if err != nil { 35 | log.Fatalf("failed to listen: %v", err) 36 | } 37 | 38 | if err := s.Serve(lis); err != nil { 39 | log.Fatalf("failed to serve: %v", err) 40 | } 41 | } 42 | 43 | func (s server) AddProduct(context.Context, *pb.Product) (*pb.ProductID, error) { 44 | panic("implement me") 45 | } 46 | 47 | func (s server) GetProduct(context.Context, *pb.ProductID) (*pb.Product, error) { 48 | panic("implement me") 49 | } -------------------------------------------------------------------------------- /docs/diagram/productinfo.drawio: -------------------------------------------------------------------------------- 1 | 7Zhbb9sgFMc/jR872RBf8pimXVdN0ypF3bKniRpioxGTYdI4/fSDGN+w0/SWbJP6FM45cAz8fz7yiQOny+JKoFX6hWPCHODiwoEXDgCeDz31oz3b0hOEbulIBMVmUuOY0QdinNW0NcUk70yUnDNJV11nzLOMxLLjQ0LwTXfagrPuU1coIT3HLEas7/1OsUxLL3Bdtwl8IjRJpR1Zomq2ceQpwnzTcsFLB04F57IcLYspYfr2qosp133cE613Jkgmn7LgK3qIcvdbcPv5ZzG/Ps9uz+byzGS5R2xtTuyAgKl85wuu0qpdy625i+D3mleBs3yn1ERN8KJV0QTVKNG/U0b1tkwutakyXRk091FnBoKvM0z0Pl0V3qRUktkKxTq6UVwpXyqXTFmeGuZS8F+1GkDviDI25YyLXTaIEYkWcT2zFQniiNwt6h3cEyFJsfc6vVokhTfhSyLFVk0xC0BkdDVke4GxNw0n1ZS0S4jB06CZ1Kkb8dTA6PcMLcGRtLwRHK/jWsw7UQWuswXve2dEqIvt+/8SDD6J8GgIhgjcwSB4GxgC91+DYTQAg3XRJMMTXSKVFTOU5zTu3q06u9jOjQ4744c2PgC/si+KdvRiW1kFlfMqiRq3lymzWaWNalFfyXLDBPcqtKWKOhRfi5gcLnMSiYTIQ69QX+WWiv6AipVPEIYkve9ud0hZ84QbTnfv5Z6KMoIWHOUxzap2pbcSQdhNBCMrUXkPvUQ70Opjv5y94PXs9WmooHI7UMFHmdLGDRFUHYiINqo1nQ3V8BDU2rKTvSGi4ImI7ilEp0HU97tkgfCliAZWInBaRKOjILqnYIYvK5jh4wXzvTz+p+VxfLryGI4fZ+g5BTJ6L5CHIQ08q65BK8WTIQ3tRKeF1HuDztAf6iYmGFsNxaGGQH2WyyH8q2/5jGfE+vA3LsRokul3SMGmkTzXH/lUdfcTE1hSjPVjBtuMbiPivL5LGI2sLmHc7xLGg13Cfgxf1SR44ZFEvlJkvotcinc8kZXZ/H1UvvjNv3Dw8g8= -------------------------------------------------------------------------------- /examples/security/oauth2/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "golang.org/x/oauth2" 6 | "google.golang.org/grpc/credentials/oauth" 7 | "log" 8 | "time" 9 | 10 | "google.golang.org/grpc" 11 | "google.golang.org/grpc/credentials" 12 | pb "grpc-up-and-running/examples/security/oauth2/client/ecommerce" 13 | ) 14 | 15 | var ( 16 | address = "localhost:50051" 17 | hostname = "localhost" 18 | crtFile = "server.crt" // server public certificate. 19 | ) 20 | 21 | func main() { 22 | auth := oauth.NewOauthAccess(fetchToken()) 23 | 24 | creds, err := credentials.NewClientTLSFromFile(crtFile, hostname) 25 | if err != nil { 26 | log.Fatalf("failed to load credentials: %v", err) 27 | } 28 | 29 | opts := []grpc.DialOption{ 30 | grpc.WithPerRPCCredentials(auth), 31 | grpc.WithTransportCredentials(creds), 32 | } 33 | 34 | conn, err := grpc.Dial(address, opts...) 35 | if err != nil { 36 | log.Fatalf("did not connect: %v", err) 37 | } 38 | defer conn.Close() 39 | c := pb.NewProductInfoClient(conn) 40 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 41 | defer cancel() 42 | 43 | // Call remote methods 44 | c.AddProduct(ctx, nil) 45 | c.GetProduct(ctx, nil) 46 | } 47 | 48 | 49 | func fetchToken() *oauth2.Token { 50 | return &oauth2.Token{ 51 | AccessToken: "some-secret-token", 52 | } 53 | } -------------------------------------------------------------------------------- /docs/diagram/jwt.drawio: -------------------------------------------------------------------------------- 1 | 3Vhbb5swGP01eWwFNiH0MUu6btIqTYq0tY8OfAlWHZyCc+uv3wfY3OI0XUUv2xP2+ezPl3PMMQzoZLW/Sdk6vpURiAFxov2ATgeEuNQh+MiRQ4mMHLcElimPdKMamPEn0KCj0Q2PIGs1VFIKxddtMJRJAqFqYSxN5a7dbCFFe9Q1W8IRMAuZOEZ/80jFGr0iTh34BnwZm6GJoyMrZlprIItZJHcNiF4P6CSVUpWl1X4CIt89szFlv68notXMUkjUSzp8/0HI9fZppNZXF+HqVjwsRuxCZ9kysdErHhBfYL4vC4lpcdbqoPfCf9xIE7jICqbG2MAN1vs6iKWlfhZZ5gaYCJ7PU8M4y3m3KWLlmAYmreFJKjdJBPliXAzvYq5gtmZhHt2h+BCL1UrocKZS+VBRRvJpcyEmUsi0yEajIQSRV7VsRAIyp75fzWALqYL9yT13KybxDIBcgUoP2ER3qNSg5U8CXd/VYjJQ3JCRwZiW77LKXBOMBc3xX/BN3ovvGaS4c5+IbwbBIrTx7YcBzBf98O17n4xvepZv88o1jLrPkvsCffg2fYw3KsY95CFTXCbY7MP10QPbXud0u+SY7Qp7F7o9C92dbYMkGufGiLVQsCzj4bmdgj1Xd1h2dPk+L1+Ohro63Tdi04OpJLieu0bLvH7fDNb9iprpWE4YoiNf7rCCi5KbNITz4lcsXYI6Z4LHLDdYHFpINFgKAkW9bU/Xxqwe4afkxckzrwzaFpHndsRRLlP3avp7N1HQTkT9TqJyH44SFUKrlv167QVvor1KRi0NXQ7PqMho1m1p9nnJ9qg8c1U9pzzykcrzOmY19F6pvOqK+0HKMyfG4nJHrvLiaw612dgN5J1ZGEKWFZ8iD5Cc9CubtXUOBHqPsh0Bcz1JZAKdu4yGmODLJD9HqE30UfoldzK0VzHWgRWPonwYqzPW3ukUNVXaMp1S4vV08x11bkKOxRtdi7jpW3mje/pbp2eVzPA9VxzPxw1kqlgzLvm/kUsP6qAdryJXFnX476qO019GPavjF3IRMQW1IJx5vjVcZSAW/748Gm+TntTiO0O7vzTVYjPKV6gFq/UvmdKg6j9b9PoP -------------------------------------------------------------------------------- /docs/diagram/oauth2.drawio: -------------------------------------------------------------------------------- 1 | 3Zhbb9owFMc/DY+tEjsJ4ZFC101apUlIW/tokgOxamLqmFs//ZzEzo0wGApQ9Yn4HPv48v/ZPqaHR4vtkyDL6JmHwHrICrc9PO4hZGMLqZ/UssstfdfKDXNBQ12pNEzoB2ijqbaiISS1ipJzJumybgx4HEMgazYiBN/Uq804q/e6JHPYM0wCwvatf2goI20dIKt0fAc6j0zXyNKeBTG1tSGJSMg3FRN+7OGR4FzmX4vtCFi6emZh8nbfDniLkQmI5SkNfvxE6HH90ZfLwV2weGZvsz6501HWhK30jHvIYyrew4yrsGrUcqfXwntfceO4SzKlhqqC7S+3pVN9zfVvFmVqDCNG03FqsxrltFlV2fI+jRnVukeCr+IQ0snYyr2JqITJkgSpd6PgU7ZILph2J1Lwt0IylA6bMjbijIssGg5d8EOnqFnx+GiKPa8YwRqEhO3BNbcLJdUeAL4AKXaqim5Q0KDxR74ub0qYjCmqYGRsROM7LyKXAqsPrfF/6I2upfcEhFq5T6Q3AX8WtOntBT5MZ93o7TmfTG98Lb2HKxlxQT+IpDxWzW6ufwdqOo3da6N9NQvbVeR0WuRsLBvE4TC9+FQpYCRJaHBspWBL5Yv6tvT3a/p933d1cbyt+MY7U4jVfF4qNdPya9VZtstKpmE+YAj37t2GKmpSfCUCOA63JGIO8tglt69yRUW3RURjE8AU1Ov6cNuU1T384jTbWeZIwHWIHLsBRz5N3ap6fzcD+fVA2GsEytdhL1AGWjHt89nzL8JegVGNoXv3CEWGWbvG7L+R7ZA8k4oeIw/dkjyncRm5zpnkFSnsjcgbXJQ8u05e/1T0rHvkVum7FnvoRPbwLdlDgwYy+NxTzz0S6MLsmdO6JYPay2hOTqlwW0r1BGljEgSQJNkz9w3ig7lSW1rV2BIq75Ftm8CkvjGPoZEnaxNhdB6nO0mxqXI4/JBmUVQ9iofasaBhmHbTmpWVeZuVlWSeEuIxRk5Hr6p+I8u2WvIyuwXuJjud5WX24Xd0x5RM1EmXbc/3FSQym7Oa8pfBpQM6cCNPKo6iKh3eVek4/OrumI7fSouQSPg6QFTPD7cbQNzmI/2Cx4cqlv/w5XdS+UcpfvwL -------------------------------------------------------------------------------- /productinfo/service/productinfo_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gofrs/uuid" 7 | "google.golang.org/grpc/codes" 8 | "google.golang.org/grpc/status" 9 | pb "productinfo/service/ecommerce" 10 | ) 11 | 12 | // server is used to implement ecommerce/product_info. 13 | type server struct { 14 | productMap map[string]*pb.Product // Create a map for storing Product records. 15 | } 16 | 17 | // Add a product. 18 | // This method will generate a new UUID as Product ID and store the Product into a map. 19 | // This method will return the Product ID. 20 | func (s *server) AddProduct(ctx context.Context, in *pb.Product) (*pb.ProductID, error) { 21 | out, err := uuid.NewV4() 22 | if err != nil { 23 | return nil, status.Errorf(codes.Internal, "Error while generating Product ID", err) 24 | 25 | } 26 | in.Id = out.String() 27 | if s.productMap == nil { 28 | s.productMap = make(map[string]*pb.Product) 29 | } 30 | s.productMap[in.Id] = in 31 | return &pb.ProductID{Value: in.Id}, status.New(codes.OK, "").Err() 32 | 33 | } 34 | 35 | // Get a product by product ID. 36 | // This method will check the Product record is existing or not in the map 37 | func (s *server) GetProduct(ctx context.Context, in *pb.ProductID) (*pb.Product, error) { 38 | value, exists := s.productMap[in.Value] 39 | if exists { 40 | return value, status.New(codes.OK, "").Err() 41 | } 42 | return nil, status.Errorf(codes.NotFound, "Product does not exist.", in.Value) 43 | } 44 | -------------------------------------------------------------------------------- /docs/diagram/tls.drawio: -------------------------------------------------------------------------------- 1 | 3ZjbcpswEIafxjPtRTIgDHYufUjTmU5n0iSTw6UAAZrIyJXl2OTpuzISJ0PqurbTJhcx2l2txf4f0uKeM5mtrwSeJ995SFgPWeG650x7CNmOheBDWbLcMrDs3BALGuqg0nBLX4k2Wtq6pCFZ1AIl50zSed0Y8DQlgazZsBB8VQ+LOKt/6xzHZMtwG2C2bX2goUy09QJZpeMroXFivhpZ2jPDJlobFgkO+apici57zkRwLvOr2XpCmKqeKUw+70uHt1iZIKncaQJ7zab3N5z+CNLkevVwdXOHz3SWF8yW+o57yGOQbxxxSAurlpmuhfdzyY3jbLFRagQB9mC+Lp1wFavPCaNqWToXLCpPlzt1PYrMSPBlGhK1Thvcq4RKcjvHgfKugCuwJXLGtHshBX8u1EBqRZSxCWdcbLI5oUuGYb+IrHiGyHc8r1jBCxGSrDvLaRciAd6Ez4gUGYSYCZ7WVZON+nq8KjkZalNSIcTYsCYzLjKX2sGFlu8PpERHkvKWCCjUO0mJyTAK2qT0giHxo8NIOfjXpHSO9VRClWhEAywJxIyWMuGCyswk94UJ/DQZfd62vg8DURShoJWB0PM990CPc79fZ2C4jYCNTslAv4WBRp1JGo7UGQejgOHFgga/Ky0UQ2SPMLDM4EkNzl0znK6rzmlmRmsqH8tIGD1VPOUkNTBz8uWScOuAbUgCt8SXIiBv1MKc/FjERL4R57RLXNHQbZHQ2ARhWNKX+nLbdNXfcM3p5mHUBHl2nSCn30Ajv009q3pQNxM1t6OLRqK8DluJNpgVt70/ee5RybNr5O3KXZW684F7KvCcHcHr2FtOA55rdRxffwte0eKcCLzhCcHbfcuroXcy8tD/QN6H2fLs7vcgv+iDE5ARYkw/bF0vfQb8IavWVhUtkt/ZH0GXIuvYYkbjVDENnEBuZ6x6GUjIRtoxo2Gopo8FgSYP+5tUCrm5KsmmSO64507BwrBP2BgHz/GmD6t3UvD3Vr+kX6N1/h4qX3MrBHc+utsYajkNzfviZkJ4FC3IcQBoO/SaAMDm06r/N6Lu9Y7Dv3siaJTtSUG9wU15ShrdsDbtTktb711259ZmJEESrmY5jnOYXhrZHedIZVcqfiepbkvoWM203Xa0NOS9UmRZkxG8RcUpCQ/yXH8YRYcNRdtej9oOmj0UhWH5o1j+fJe/LTqXvwA= -------------------------------------------------------------------------------- /examples/grpc-gateway/server/productinfo_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gofrs/uuid" 7 | "google.golang.org/grpc/codes" 8 | "google.golang.org/grpc/status" 9 | pb "examples/grpc-gateway/server/ecommerce" 10 | ) 11 | 12 | // server is used to implement ecommerce/product_info. 13 | type server struct { 14 | productMap map[string]*pb.Product // Create a map for storing Product records. 15 | } 16 | 17 | // Add a product. 18 | // This method will generate a new UUID as Product ID and store the Product into a map. 19 | // This method will return the Product ID. 20 | func (s *server) AddProduct(ctx context.Context, in *pb.Product) (*pb.ProductID, error) { 21 | out, err := uuid.NewV4() 22 | if err != nil { 23 | return nil, status.Errorf(codes.Internal, "Error while generating Product ID", err) 24 | 25 | } 26 | in.Id = out.String() 27 | if s.productMap == nil { 28 | s.productMap = make(map[string]*pb.Product) 29 | } 30 | s.productMap[in.Id] = in 31 | return &pb.ProductID{Value: in.Id}, status.New(codes.OK, "").Err() 32 | 33 | } 34 | 35 | // Get a product by product ID. 36 | // This method will check the Product record is existing or not in the map 37 | func (s *server) GetProduct(ctx context.Context, in *pb.ProductID) (*pb.Product, error) { 38 | value, exists := s.productMap[in.Value] 39 | if exists { 40 | return value, status.New(codes.OK, "").Err() 41 | } 42 | return nil, status.Errorf(codes.NotFound, "Product does not exist.", in.Value) 43 | } 44 | -------------------------------------------------------------------------------- /docs/install_protocol_buffer_compiler.md: -------------------------------------------------------------------------------- 1 | ## Install Protocol Buffer Compiler 2 | ### For Ubuntu/Debian 3 | ```bash 4 | $ sudo apt-get install autoconf automake libtool curl make g++ unzi 5 | ``` 6 | ### For Other Platforms 7 | - **Step 1**: Download the source code. 8 | - **Way 1**: Download from Github. 9 | - Use this link to download: [https://github.com/protocolbuffers/protobuf/releases/latest](https://github.com/protocolbuffers/protobuf/releases/latest) 10 | - Pick the right version 11 | 12 | | Language | Pick This File | 13 | |---|---| 14 | | C++ | protobuf-cpp-[VERSION].(tar.gz\|zip) | 15 | | Java | protobuf-java-[VERSION].(tar.gz\|zip) | 16 | | C# | protobuf-csharp-[VERSION].(tar.gz\|zip) | 17 | | JavaScript | protobuf-csharp-[VERSION].(tar.gz\|zip) | 18 | | Objective-C | protobuf-objectivec-[VERSION].(tar.gz\|zip) | 19 | | PHP | protobuf-php-[VERSION].(tar.gz\|zip) | 20 | | Python | protobuf-python-[VERSION].(tar.gz\|zip) | 21 | | Ruby | protobuf-ruby-[VERSION].(tar.gz\|zip) | 22 | | All Languages | protobuf-all-[VERSION].(tar.gz\|zip) | 23 | - **Way 2**: Clone from Github. 24 | ```bash 25 | git clone https://github.com/protocolbuffers/protobuf.git 26 | cd protobuf 27 | git submodule update --init --recursive 28 | ./autogen.sh 29 | ``` 30 | - **Step 2**: Install the source code. 31 | ```bash 32 | ./configure 33 | make 34 | make check 35 | sudo make install 36 | ``` 37 | 38 | -------------------------------------------------------------------------------- /examples/grpc-gateway/postman/gRPC-Gateway.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "c8c604a5-5bf8-40a3-ab5e-36ddc67f7482", 4 | "name": "gRPC-Gateway", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "http://localhost:8081/v1/product", 10 | "request": { 11 | "method": "POST", 12 | "header": [], 13 | "body": { 14 | "mode": "raw", 15 | "raw": "{\"name\": \"Apple\", \"description\": \"iphone7\", \"price\": 699}", 16 | "options": { 17 | "raw": { 18 | "language": "json" 19 | } 20 | } 21 | }, 22 | "url": { 23 | "raw": "http://localhost:8081/v1/product", 24 | "protocol": "http", 25 | "host": [ 26 | "localhost" 27 | ], 28 | "port": "8081", 29 | "path": [ 30 | "v1", 31 | "product" 32 | ] 33 | } 34 | }, 35 | "response": [] 36 | }, 37 | { 38 | "name": "http://localhost:8081/v1/product/f7e2bc30-e51a-4840-a45a-0c5b676f58d4", 39 | "request": { 40 | "method": "GET", 41 | "header": [], 42 | "url": { 43 | "raw": "http://localhost:8081/v1/product/f7e2bc30-e51a-4840-a45a-0c5b676f58d4", 44 | "protocol": "http", 45 | "host": [ 46 | "localhost" 47 | ], 48 | "port": "8081", 49 | "path": [ 50 | "v1", 51 | "product", 52 | "f7e2bc30-e51a-4840-a45a-0c5b676f58d4" 53 | ] 54 | } 55 | }, 56 | "response": [] 57 | } 58 | ], 59 | "protocolProfileBehavior": {} 60 | } -------------------------------------------------------------------------------- /ordermgt/client/name_resolver.go: -------------------------------------------------------------------------------- 1 | // gRPC name resolver implementation. 2 | // Resolves lb.example.grpc.io to localhost:50051 and localhost:50052. 3 | package main 4 | 5 | import "google.golang.org/grpc/resolver" 6 | 7 | const ( 8 | exampleScheme = "example" 9 | exampleServiceName = "lb.example.grpc.io" 10 | ) 11 | 12 | var addrs = []string{"localhost:50051", "localhost:50052"} 13 | 14 | type exampleResolverBuilder struct{} 15 | 16 | func (*exampleResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { 17 | r := &exampleResolver{ 18 | target: target, 19 | cc: cc, 20 | addrsStore: map[string][]string{ 21 | exampleServiceName: addrs, // "lb.example.grpc.io": "localhost:50051", "localhost:50052" 22 | }, 23 | } 24 | r.start() 25 | return r, nil 26 | } 27 | func (*exampleResolverBuilder) Scheme() string { return exampleScheme } // "example" 28 | 29 | type exampleResolver struct { 30 | target resolver.Target 31 | cc resolver.ClientConn 32 | addrsStore map[string][]string 33 | } 34 | 35 | func (r *exampleResolver) start() { 36 | addrStrs := r.addrsStore[r.target.Endpoint] 37 | addrs := make([]resolver.Address, len(addrStrs)) 38 | for i, s := range addrStrs { 39 | addrs[i] = resolver.Address{Addr: s} 40 | } 41 | r.cc.UpdateState(resolver.State{Addresses: addrs}) 42 | } 43 | func (*exampleResolver) ResolveNow(o resolver.ResolveNowOptions) {} 44 | func (*exampleResolver) Close() {} 45 | 46 | func init() { 47 | resolver.Register(&exampleResolverBuilder{}) 48 | } 49 | -------------------------------------------------------------------------------- /examples/security/two-way-tls/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "crypto/x509" 7 | "io/ioutil" 8 | "log" 9 | "time" 10 | 11 | pb "grpc-up-and-running/examples/security/two-way-tls/client/ecommerce" 12 | "google.golang.org/grpc/credentials" 13 | "google.golang.org/grpc" 14 | ) 15 | 16 | var ( 17 | address = "localhost:50051" 18 | hostname = "localhost" 19 | crtFile = "client.crt" 20 | keyFile = "client.key" 21 | caFile = "ca.crt" 22 | ) 23 | 24 | func main() { 25 | cert, err := tls.LoadX509KeyPair(crtFile,keyFile) 26 | if err != nil { 27 | log.Fatalf("failed to load credentials: %v", err) 28 | } 29 | 30 | certPool := x509.NewCertPool() 31 | ca, err := ioutil.ReadFile(caFile) 32 | if err != nil { 33 | log.Fatalf("could not read ca certificate: %s", err) 34 | } 35 | if ok := certPool.AppendCertsFromPEM(ca); !ok { 36 | log.Fatalf("failed to append ca certs") 37 | } 38 | 39 | opts := []grpc.DialOption{ 40 | grpc.WithTransportCredentials( credentials.NewTLS(&tls.Config{ 41 | ServerName: hostname, // ServerName must be equal to the Common Name on the certificate. 42 | Certificates: []tls.Certificate{cert}, 43 | RootCAs: certPool, 44 | })), 45 | } 46 | 47 | conn, err := grpc.Dial(address, opts...) 48 | if err != nil { 49 | log.Fatalf("did not connect: %v", err) 50 | } 51 | defer conn.Close() 52 | c := pb.NewProductInfoClient(conn) 53 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 54 | defer cancel() 55 | 56 | // Call remote methods 57 | c.AddProduct(ctx, nil) 58 | c.GetProduct(ctx, nil) 59 | } 60 | -------------------------------------------------------------------------------- /productinfo/service/productinfo_test.go: -------------------------------------------------------------------------------- 1 | // Normal test for AddProduct 2 | package main 3 | 4 | import ( 5 | "context" 6 | "google.golang.org/grpc" 7 | "google.golang.org/grpc/reflection" 8 | "log" 9 | "net" 10 | pb "grpc-gateway/server/ecommerce" 11 | "testing" 12 | "time" 13 | ) 14 | 15 | const ( 16 | address = "localhost:50051" 17 | ) 18 | 19 | func initGRPCServerHTTP2() { 20 | lis, err := net.Listen("tcp", port) 21 | 22 | if err != nil { 23 | log.Fatalf("failed to listen: %v", err) 24 | } 25 | s := grpc.NewServer() 26 | pb.RegisterProductInfoServer(s, &server{}) 27 | // Register reflection server on gRPC server. 28 | reflection.Register(s) 29 | go func() { 30 | if err := s.Serve(lis); err != nil { 31 | log.Fatalf("failed to serve: %v", err) 32 | } 33 | }() 34 | } 35 | 36 | 37 | // Test AddProduct 38 | func TestServer_AddProduct(t *testing.T) { 39 | initGRPCServerHTTP2() // Starting a conventional gRPC server runs on HTTP2 40 | conn, err := grpc.Dial(address, grpc.WithInsecure()) 41 | if err != nil { 42 | log.Fatalf("did not connect: %v", err) 43 | } 44 | defer conn.Close() 45 | c := pb.NewProductInfoClient(conn) 46 | 47 | // Contact the server and print out its response. 48 | name := "Sumsung S10" 49 | description := "Samsung Galaxy S10 is the latest smart phone, launched in February 2019" 50 | price := float32(700.0) 51 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 52 | defer cancel() 53 | r, err := c.AddProduct(ctx, &pb.Product{Name: name, Description: description, Price: price}) 54 | if err != nil { 55 | log.Fatalf("Could not add product: %v", err) 56 | } 57 | log.Printf("Res %s", r.Value) 58 | } 59 | -------------------------------------------------------------------------------- /docs/diagram/mtls.drawio: -------------------------------------------------------------------------------- 1 | 7VrbkuI2EP0aqpKH2bIlbOCRy2ZSlUrVZGdrL4+yLWPVCosIMcB+fdpY8kW2Z1kChkxlHgar1WrLfY663Q0DPF/tHyVZJ3+KiPIBcqL9AC8GCLnYQfCRSQ65ZOS4uWApWaSVSsEz+0610NHSLYvopqaohOCKrevCUKQpDVVNRqQUu7paLHj9rmuypA3Bc0h4U/qZRSrR0glyyonfKVsm5tbI0TMrYrS1YJOQSOwqIvx+gOdSCJVfrfZzyjPvGcfk637rmC12JmmqTlrAvx8Wnz4I9leYJk+7z48fPpIHbeWF8K1+4gHyOdibxQLMwq7VQfvC/3srzMTD5ojUFBTc0XpfTsLVMvucc5ZtS9uCTeXm8kntj8IykmKbRjTbpwvTu4Qp+rwmYTa7A16BLFErrqc3SopvBRoo2xHjfC64kEdrOPLoOBoWmpWZMQqw7xc7eKFS0X2nO90CJKA3FSuq5AFUzAJf46qZjYZ6vCt5MtaipMIQIyOamcvCcokdXGj4fgJKdCUon6kER90ISkLHcdgGpR+OaRBfBsrRvUGJr3UqwUssZiFRFHSmW5UIydTBGA+kUfxlPv21Kb0NB+I4RmErByI/8L0LHefhsM6BcZMCLuqTA8MWDlh+pmk0zXIcjEJONhsW/si14Ax5+AIDxwy+ZoN3nhku9tXJxcGM9kx9KTVh9LUyUy7KBmZNvl0aNRKsBQk8ktjKkL7iC5P5iVxS9Yoeboe4gqHXAqGRScqJYi/17bbhqu/wJNjxMGoG+W6dQXhoUSN/TL2qmqhtQ3Y4mliGcj80DB1pVjz2+czzrso8t8a8U3lXZd27kdcX8fCJxOuILf0Qz3M60te/JV7xitMT8fweiXfvIQ/9F0LecGIxD53JPDyyDNlp9crMG/WYbE/knXvnIQ/dknjYJp5zJvGQTbyeQ974LkNejXq9Me/UkHfTZPtm3vLc7tZPUJT+CcAIOqYF4DxtAw78Q06tkiyqwqCzJITCTNVpSzhbphmngSdgG8+y8g0M8qmeWLEoypbPJIW6lgRHUxnl1plLjk7yZgNvARJOAspnJPy2PJae9eIR/l4rEXXnUNsfoLKzV2Fw59Ft0lDDadh8Lt2MiojjDb0KASY95jydv+447Z1aYt407fnWmz62s9WpwWeE6oaG9ovbtYNPd4erEXxMK/n/4GMf3s7gc/exx23rMdj4Q/RpzT1/0OxRPwr494lKFh/OJEG9n5iKlFrNRy06nSxtrc6yGeocRwogEdkqjPFlWpfI7SjbK0GpeEGuRiX70F+sd+m2VfLt8DZP9xuBF40ug643+TG67qRXdNuqZQvdxyxuOPPpwwZ8SKOLBO23AqhVcrptXzW0vURcD9C2KvTtA3q5ADzuD1EYlj8ZyNNx+csL/P4f -------------------------------------------------------------------------------- /docs/diagram/gateway.drawio: -------------------------------------------------------------------------------- 1 | 7Vrbcts2EP0azaQP0ZAEb3q05cRpZzqjxunUfoRIUEJMESwEWVK/voAI3kDQVmKI0sSWH0wsFiC4Z3cPFuQITFe7Wwrz5Z8kRunIseLdCNyMHMcGlsP/Ccm+kASWXQgWFMdSqRbc4f+QFFpSusExWrcUGSEpw3lbGJEsQxFrySClZNtWS0javmsOF6gjuItg2pX+g2O2LKSOZVl1xxeEF0um9qxgqS0F6yWMybYhAp9GYEoJYcXVajdFqbBeaZhi3Oee3mplFGXsmAF/3D7e51v41+N3Yrn3yyX4+/fPH22JzxNMN/KR5WrZvrQBJZssRmIWawSut0vM0F0OI9G75ahz2ZKtUt6y+eWaUfJY2Yo/5HWC03RKUkIPs4HEE3+VZqPHP/zECJKxhrz4cblcKqIM7XqNYFem5U6JyAoxuucqcoAbSDSkP1bobGt0PVfKlg1gbV8KofSoRTV3bXN+Ic3+IxAMjUDsoTB2dQiEzhwcEDBh6YliabdraTvUWdo5laV1vu6nTHpcy+T+vxtSdnxcH9LSFVew/XxXd/Krhfx/mGVeCr4ibro14gNmlOyEUe4Q5aJSka9+rg7msmIVpVjxAY4E0wFdwpeRDClYSxFM8SLjzYgjx9cArgWumOe4K9mxwnEsbqP1rLbvGXEMr+0YvsYxAo1jnMwvwOARCFGYRNocGIVonpgxdGhfXAS6Q0WgjLufDzfDpBdGKNICPg891zMUWZ7tjNuxBSwN5MDrQu6eCvGgF/F1DjODiC++zqbHJtri1r96og1dJf51idYZMtGGQ4X/HdvM31r0h+Dyon/yMrOiLL4ShZqImxSu1zhqW5c/Pd3fSyQOjQfRGAde2b7ZNXtv9mVrh9l9OQm/bg7jzXqUaJSD2ljWRQeKO3Wiggt/KLKhEXp5p88gXSD20n6ki3OzRNFEbSmjKIUMP7WXq0NW3mFG8CH2pBv5StYAoeIcxWPKUc16U51IKQAAUCYq7NCZ6OBo1WO/oq6yBqaeKRSLeieeLvK2Jg9ZQxKPrSuyT8I8X759mwlfSDE68MulUFCSOHoKiv257xmq+W1wcRWHfURx95Yo6FgO6gF6GA5yvbYfefZPcpA3eWGiU3NQf8FrmIPKvPPOQZJz1G3M+TnIG4qDZpQwEhGxoutNkohy2JqSVY7T1x1BmqYk5PdQUjCZW6b2In7bD1wdJfkaPzjdeb//ekbqckRJNdbYKenlockuWqqpiW1cUdlDk/R6eE1BEtmxhwIdkhM/ANDviW8zhOYdSWjuOQnt7EUV9ya4b6jlQmHdv+DAUsJGfbmoEm34rD6/KFZgll11h4sGIyl4j6TeU7xzRZJtKaFU7RV/NJQmjhJK6kSmQun50Oiu6/nQO1EoDXc0i+gTjsS70RuU4AwzTLJKiZZaH8a52MT81u25oA3MWb9kUDc2Hjj7xsbAae9z6fhtZePwyGxcpO1zpeNgYiob26azselavqSL06fIW5QhClnj+5H3z0a6O0zty60hC3pnsEPlhkO89s3mL+MPnW2Vzh8Mvd3mzfo7zSKf1J+7gk//Aw== -------------------------------------------------------------------------------- /examples/security/two-way-tls/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "crypto/x509" 7 | "google.golang.org/grpc" 8 | "google.golang.org/grpc/credentials" 9 | pb "grpc-up-and-running/examples/security/two-way-tls/server/ecommerce" 10 | "io/ioutil" 11 | "log" 12 | "net" 13 | ) 14 | 15 | type server struct {} 16 | 17 | var ( 18 | port = ":50051" 19 | crtFile = "server.crt" // server public certificate. 20 | keyFile = "server.key" // server private key. 21 | caFile = "ca.crt" // public certificate of a CA used to sign all public certificates. 22 | ) 23 | 24 | func main() { 25 | cert, err := tls.LoadX509KeyPair(crtFile,keyFile) 26 | if err != nil { 27 | log.Fatalf("failed to load key pair: %s", err) 28 | } 29 | 30 | certPool := x509.NewCertPool() 31 | ca, err := ioutil.ReadFile(caFile) 32 | if err != nil { 33 | log.Fatalf("could not read ca certificate: %s", err) 34 | } 35 | if ok := certPool.AppendCertsFromPEM(ca); !ok { 36 | log.Fatalf("failed to append ca certificate") 37 | } 38 | 39 | opts := []grpc.ServerOption{ 40 | grpc.Creds( 41 | credentials.NewTLS(&tls.Config { 42 | ClientAuth: tls.RequireAndVerifyClientCert, 43 | Certificates: []tls.Certificate{cert}, 44 | ClientCAs: certPool, 45 | }, 46 | )), 47 | } 48 | 49 | s := grpc.NewServer(opts...) 50 | pb.RegisterProductInfoServer(s, &server{}) 51 | 52 | lis, err := net.Listen("tcp", port) 53 | if err != nil { 54 | log.Fatalf("failed to listen: %v", err) 55 | } 56 | 57 | if err := s.Serve(lis); err != nil { 58 | log.Fatalf("failed to serve: %v", err) 59 | } 60 | } 61 | 62 | func (s server) AddProduct(context.Context, *pb.Product) (*pb.ProductID, error) { 63 | panic("implement me") 64 | } 65 | 66 | func (s server) GetProduct(context.Context, *pb.ProductID) (*pb.Product, error) { 67 | panic("implement me") 68 | } -------------------------------------------------------------------------------- /ordermgt/service/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "google.golang.org/grpc" 5 | "log" 6 | "net" 7 | ordermgt_pb "ordergmt/service/ecommerce" 8 | hello_pb "google.golang.org/grpc/examples/helloworld/helloworld" 9 | ) 10 | 11 | const ( 12 | port = ":50051" 13 | ) 14 | 15 | func main() { 16 | initSampleData() 17 | lis, err := net.Listen("tcp", port) 18 | if err != nil { 19 | log.Fatalf("failed to listen: %v", err) 20 | } 21 | s := grpc.NewServer( 22 | grpc.UnaryInterceptor(orderUnaryServerInterceptor), // Register unary interceptor. 23 | grpc.StreamInterceptor(orderServerStreamInterceptor)) // Register stream interceptor. 24 | 25 | // Register 2 services: OrderManagement and Hello 26 | // Example of Multiplexing - Run multiple services on one gRPC server 27 | ordermgt_pb.RegisterOrderManagementServer(s, &orderMgtServer{}) 28 | hello_pb.RegisterGreeterServer(s, &helloServer{}) 29 | 30 | log.Printf("Starting gRPC listener on port " + port) 31 | 32 | if err := s.Serve(lis); err != nil { 33 | log.Fatalf("failed to serve: %v", err) 34 | } 35 | } 36 | 37 | func initSampleData() { 38 | orderMap["102"] = ordermgt_pb.Order{Id: "102", Items: []string{"Google Pixel 3A", "Mac Book Pro"}, Destination: "Mountain View, CA", Price: 1800.00} 39 | orderMap["103"] = ordermgt_pb.Order{Id: "103", Items: []string{"Apple Watch S4"}, Destination: "San Jose, CA", Price: 400.00} 40 | orderMap["104"] = ordermgt_pb.Order{Id: "104", Items: []string{"Google Home Mini", "Google Nest Hub"}, Destination: "Mountain View, CA", Price: 400.00} 41 | orderMap["105"] = ordermgt_pb.Order{Id: "105", Items: []string{"Amazon Echo"}, Destination: "San Jose, CA", Price: 30.00} 42 | orderMap["106"] = ordermgt_pb.Order{Id: "106", Items: []string{"Amazon Echo", "Apple iPhone XS"}, Destination: "Mountain View, CA", Price: 300.00} 43 | } 44 | -------------------------------------------------------------------------------- /examples/security/basic-auth/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/base64" 6 | "log" 7 | "time" 8 | 9 | pb "grpc-up-and-running/examples/security/basic-auth/client/ecommerce" 10 | "google.golang.org/grpc/credentials" 11 | "google.golang.org/grpc" 12 | ) 13 | 14 | var ( 15 | address = "localhost:50051" 16 | hostname = "localhost" 17 | crtFile = "server.crt" // server public certificate. 18 | ) 19 | 20 | func main() { 21 | creds, err := credentials.NewClientTLSFromFile(crtFile, hostname) 22 | if err != nil { 23 | log.Fatalf("failed to load credentials: %v", err) 24 | } 25 | 26 | auth := basicAuth{ 27 | username: "admin", 28 | password: "admin", 29 | } 30 | 31 | opts := []grpc.DialOption{ 32 | grpc.WithPerRPCCredentials(auth), 33 | grpc.WithTransportCredentials(creds), 34 | } 35 | 36 | conn, err := grpc.Dial(address, opts...) 37 | if err != nil { 38 | log.Fatalf("did not connect: %v", err) 39 | } 40 | defer conn.Close() 41 | c := pb.NewProductInfoClient(conn) 42 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 43 | defer cancel() 44 | 45 | // Call remote methods 46 | c.AddProduct(ctx, nil) 47 | c.GetProduct(ctx, nil) 48 | } 49 | 50 | // The struct to hold the collection on fields you want to inject in your RPC calls. 51 | type basicAuth struct { 52 | username string 53 | password string 54 | } 55 | 56 | // Convert user credentials to request metadata. 57 | func (b basicAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) { 58 | auth := b.username + ":" + b.password 59 | enc := base64.StdEncoding.EncodeToString([]byte(auth)) 60 | return map[string]string{ 61 | "authorization": "Basic " + enc, 62 | }, nil 63 | } 64 | 65 | // Specify whether channel security is required to pass these credentials. 66 | func (b basicAuth) RequireTransportSecurity() bool { 67 | return true 68 | } -------------------------------------------------------------------------------- /docs/diagram/ordermgt.drawio: -------------------------------------------------------------------------------- 1 | 7Zxbl5o6FMc/jY/tIoSLPE617XnpOrOO66xOHxkSlRaNDfHWT98g4RZCQQdhpjDzINmJm5D/L5sdok7gbHP6TN3d+gtBOJjoGjpN4Hyi68CEgL9ElnNssWwtNqyoj0SjzLDwf2FhTJrtfYTDQkNGSMD8XdHoke0We6xgcyklx2KzJQmKZ925K1wyLDw3KFu/+oitY6uuaVpW8Q/2V2sm12zcpLUwhGsXkWPOBD9O4IwSwuKjzWmGg2j0koGJ3/epojbtGcVb1uQNv47ekT4f5l+XzJtaTxB9/3Z8J7wc3GAvrniiWwH392FJuFvea3YWY2H93JOk4l14UeqBNwDT3Smr5Eer6HUW+FG3hC/eqdhdXCnGI/WsU7LfIhz1U+PVx7XP8GLnelHtkXPFbWu2CXgJ8MOQUfIjVUOPeuQHwYwEhF68QQyQie20Za7GsWzoWmkPDpgyfKocTpCKxPHGZIMZPfMm4g3QEroKskGi8zHjZCpM6xwhRgKIK9Bcpa4z8fiB0O8KLfU7afkvRZgmrp5pYv6yYmXjAtND1rhb3ZdLbHmeSndkO8+a1o7u9qvTHSp0lwYab9FDFA15yQvcMPS9urHlo0HPT0KZS+FbVHgPzGlimJ/y1fNzvvSIqc+vDtPEePLZkzhZdJw4M0U58xUVzrmC7Cm+NoxKcVsSkF8/2VMP1wc/5tIVZnUTqwxETnBTIXhiozhwmX8odlcFgTjDI/Evs7UizpiOxFF8meJd+fgvObKcGkfxOJQcXZhML/t2TI27YgokTKfwJZhqRUxjZ31hqjfEtCJudYMpgFoRLwhu5NQxi450u1tOrRs5DXm/WGLeki2+NcRCYLYXYoWzq9i9XMknPxq2MeS+JOQaQHJkdIuyfRXKgtkCx03DsJo940XogT/NEeOmKbJFA8YaaFKILqWkjVOJulh/Z66nd00lJNQMu8WMVzgbM94hhF/nrphKGW9tzqBMbf+cHLRI3ptIYv8a8pLTdxMhLdhihLSuTxrGAPlWMdXvgqky0lnW1VxVhdrY1bW4j8H0rVJ66wPW1p4I2M5NAVZex6sD7piQ1pFsTCUAb103ASA9g4UdP4MFnT6EneotPoQVzsaHsIMIuaoVvthrTHYT/8M/c/uMzx1tMs5B9D+RNxlFdI92O3ON479JK/uOphQ6QKJ1Di2oQEvXqil60bYjUC1vSxqFg9bI6Vmj5BLGeVSpka7Yv+9WI9UiaJxHBY3MvjVSLQHGeVTQqPdYp8ptBz6PpK102HusM0eNauZR/xqpPgAxbI0s+No0Uu3sD/x+JMe63nOGRuujYWkkx7q+NUpONmpUHet616jRGnZQ96PSPJr2rdG4Pqq7Hxl95wywUe49LI2c16ZRo9x7UBrJ96P+NWqUew/6fmT0njM02j8alEaledS7RuP+UW3O0LdGRgvfDzZU3yktKf2AUOF7pkW5m32dlA88U0ktC5hTW5jcwF9tedHjQkWfHvgQyeh7bvAgKjY+QtFplGwV6WtjrkofOFHt9dqdclCd37fMwWfMRg6qOFDtVXbLQfUaomUOFtil3npEIUXBllBQbLc5naJQvVRpGYX/d8hleEShCgXVE7pOUTA7Q+GREg+H4chCyoJVvzoGWjsw8GL2azXxJ/2yH/2BH38D -------------------------------------------------------------------------------- /productinfo/service/productinfo_test_bufconn.go: -------------------------------------------------------------------------------- 1 | // Test for AddProduct by bufconn 2 | // bufconn can avoid the server to open up a port the client connects to. 3 | package main 4 | 5 | import ( 6 | "context" 7 | "google.golang.org/grpc" 8 | "google.golang.org/grpc/reflection" 9 | "google.golang.org/grpc/test/bufconn" 10 | "log" 11 | "net" 12 | pb "grpc-gateway/server/ecommerce" 13 | "testing" 14 | "time" 15 | ) 16 | 17 | const ( 18 | bufSize = 1024 * 1024 19 | ) 20 | 21 | var listener *bufconn.Listener 22 | 23 | func getBufDialer(listener *bufconn.Listener) func(context.Context, string) (net.Conn, error) { 24 | return func(ctx context.Context, url string) (net.Conn, error) { 25 | return listener.Dial() 26 | } 27 | } 28 | 29 | // Initialization of BufConn. 30 | // Package bufconn provides a net.Conn implemented by a buffer and related dialing and listening functionality. 31 | func initGRPCServerBuffConn() { 32 | listener = bufconn.Listen(bufSize) 33 | s := grpc.NewServer() 34 | pb.RegisterProductInfoServer(s, &server{}) 35 | // Register reflection server on gRPC server. 36 | reflection.Register(s) 37 | go func() { 38 | if err := s.Serve(listener); err != nil { 39 | log.Fatalf("failed to serve: %v", err) 40 | } 41 | }() 42 | 43 | } 44 | 45 | // Test AddProduct using Buffconn 46 | func TestServer_AddProductBufConn(t *testing.T) { 47 | ctx := context.Background() 48 | initGRPCServerBuffConn() 49 | conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(getBufDialer(listener)), grpc.WithInsecure()) 50 | if err != nil { 51 | log.Fatalf("did not connect: %v", err) 52 | } 53 | defer conn.Close() 54 | c := pb.NewProductInfoClient(conn) 55 | 56 | // Contact the server and print out its response. 57 | name := "Sumsung S10" 58 | description := "Samsung Galaxy S10 is the latest smart phone, launched in February 2019" 59 | price := float32(700.0) 60 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 61 | defer cancel() 62 | r, err := c.AddProduct(ctx, &pb.Product{Name: name, Description: description, Price: price}) 63 | if err != nil { 64 | log.Fatalf("Could not add product: %v", err) 65 | } 66 | log.Printf(r.Value) 67 | } 68 | -------------------------------------------------------------------------------- /examples/security/oauth2/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "google.golang.org/grpc" 7 | "google.golang.org/grpc/codes" 8 | "google.golang.org/grpc/credentials" 9 | "google.golang.org/grpc/metadata" 10 | "google.golang.org/grpc/status" 11 | pb "grpc-up-and-running/examples/security/oauth2/server/ecommerce" 12 | "log" 13 | "net" 14 | "strings" 15 | ) 16 | 17 | type server struct {} 18 | 19 | var ( 20 | port = ":50051" 21 | crtFile = "server.crt" // server public certificate. 22 | keyFile = "server.key" // server private key. 23 | 24 | correctToken = "some-secret-token" 25 | 26 | errMissingMetadata = status.Errorf(codes.InvalidArgument, "missing metadata") 27 | errInvalidToken = status.Errorf(codes.Unauthenticated, "invalid credentials") 28 | ) 29 | 30 | func main() { 31 | cert, err := tls.LoadX509KeyPair(crtFile, keyFile) 32 | if err != nil { 33 | log.Fatalf("failed to load key pair: %s", err) 34 | } 35 | 36 | opts := []grpc.ServerOption{ 37 | // Enable TLS for all incoming connections. 38 | grpc.Creds(credentials.NewServerTLSFromCert(&cert)), 39 | grpc.UnaryInterceptor(ensureValidToken), 40 | } 41 | 42 | s := grpc.NewServer(opts...) 43 | pb.RegisterProductInfoServer(s, &server{}) 44 | 45 | lis, err := net.Listen("tcp", port) 46 | if err != nil { 47 | log.Fatalf("failed to listen: %v", err) 48 | } 49 | 50 | if err := s.Serve(lis); err != nil { 51 | log.Fatalf("failed to serve: %v", err) 52 | } 53 | } 54 | 55 | // This method ensures a valid token exists within a request's metadata. 56 | // - If the token is missing or invalid, the interceptor blocks execution of the handler and returns an error. 57 | // - Otherwise, the interceptor invokes the unary handler. 58 | func ensureValidToken(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, 59 | handler grpc.UnaryHandler) (interface{}, error) { 60 | md, ok := metadata.FromIncomingContext(ctx) 61 | if !ok { 62 | return nil, errMissingMetadata 63 | } 64 | if !valid(md["authorization"]) { 65 | return nil, errInvalidToken 66 | } 67 | return handler(ctx, req) 68 | } 69 | 70 | // Validates the token. 71 | func valid(authorization []string) bool { 72 | if len(authorization) < 1 { 73 | return false 74 | } 75 | token := strings.TrimPrefix(authorization[0], "Bearer ") 76 | return token == correctToken 77 | } 78 | 79 | func (s server) AddProduct(context.Context, *pb.Product) (*pb.ProductID, error) { 80 | panic("implement me") 81 | } 82 | 83 | func (s server) GetProduct(context.Context, *pb.ProductID) (*pb.Product, error) { 84 | panic("implement me") 85 | } -------------------------------------------------------------------------------- /examples/security/basic-auth/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "encoding/base64" 7 | "google.golang.org/grpc" 8 | "google.golang.org/grpc/codes" 9 | "google.golang.org/grpc/credentials" 10 | "google.golang.org/grpc/metadata" 11 | "google.golang.org/grpc/status" 12 | pb "grpc-up-and-running/examples/security/basic-auth/server/ecommerce" 13 | "log" 14 | "net" 15 | "strings" 16 | ) 17 | 18 | type server struct {} 19 | 20 | var ( 21 | port = ":50051" 22 | crtFile = "server.crt" // server public certificate. 23 | keyFile = "server.key" // server private key. 24 | 25 | username = "admin" // correct username 26 | password = "admin" // correct password 27 | 28 | errMissingMetadata = status.Errorf(codes.InvalidArgument, "missing metadata") 29 | errInvalidToken = status.Errorf(codes.Unauthenticated, "invalid credentials") 30 | ) 31 | 32 | func main() { 33 | cert, err := tls.LoadX509KeyPair(crtFile, keyFile) 34 | if err != nil { 35 | log.Fatalf("failed to load key pair: %s", err) 36 | } 37 | 38 | opts := []grpc.ServerOption{ 39 | // Enable TLS for all incoming connections. 40 | grpc.Creds(credentials.NewServerTLSFromCert(&cert)), 41 | grpc.UnaryInterceptor(ensureValidBasicCredentials), 42 | } 43 | 44 | s := grpc.NewServer(opts...) 45 | pb.RegisterProductInfoServer(s, &server{}) 46 | 47 | lis, err := net.Listen("tcp", port) 48 | if err != nil { 49 | log.Fatalf("failed to listen: %v", err) 50 | } 51 | 52 | if err := s.Serve(lis); err != nil { 53 | log.Fatalf("failed to serve: %v", err) 54 | } 55 | } 56 | 57 | // This method ensures a valid token exists within a request's metadata. 58 | // - If the token is missing or invalid, the interceptor blocks execution of the handler and returns an error. 59 | // - Otherwise, the interceptor invokes the unary handler. 60 | func ensureValidBasicCredentials(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { 61 | md, ok := metadata.FromIncomingContext(ctx) 62 | if !ok { 63 | return nil, errMissingMetadata 64 | } 65 | if !valid(md["authorization"]) { 66 | return nil, errInvalidToken 67 | } 68 | // Continue execution of handler after ensuring a valid token. 69 | return handler(ctx, req) 70 | } 71 | 72 | // Validates the credentials. 73 | func valid(authorization []string) bool { 74 | if len(authorization) < 1 { 75 | return false 76 | } 77 | token := strings.TrimPrefix(authorization[0], "Basic ") 78 | return token == base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) 79 | } 80 | 81 | func (s server) AddProduct(context.Context, *pb.Product) (*pb.ProductID, error) { 82 | panic("implement me") 83 | } 84 | 85 | func (s server) GetProduct(context.Context, *pb.ProductID) (*pb.Product, error) { 86 | panic("implement me") 87 | } -------------------------------------------------------------------------------- /examples/loadbalancing/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "time" 8 | 9 | "google.golang.org/grpc" 10 | ecpb "google.golang.org/grpc/examples/features/proto/echo" 11 | "google.golang.org/grpc/resolver" 12 | ) 13 | 14 | const ( 15 | exampleScheme = "example" 16 | exampleServiceName = "lb.example.grpc.io" 17 | ) 18 | 19 | var addrs = []string{"localhost:50051", "localhost:50052"} 20 | 21 | func callUnaryEcho(c ecpb.EchoClient, message string) { 22 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 23 | defer cancel() 24 | r, err := c.UnaryEcho(ctx, &ecpb.EchoRequest{Message: message}) 25 | if err != nil { 26 | log.Fatalf("could not greet: %v", err) 27 | } 28 | fmt.Println(r.Message) 29 | } 30 | 31 | func makeRPCs(cc *grpc.ClientConn, n int) { 32 | hwc := ecpb.NewEchoClient(cc) 33 | for i := 0; i < n; i++ { 34 | callUnaryEcho(hwc, "this is examples/load_balancing") 35 | } 36 | } 37 | 38 | func main() { 39 | // Case 1: Use pick_first load-balancing policy to build connection 40 | pickfirstConn, err := grpc.Dial( 41 | fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName), // "example:///lb.example.grpc.io" 42 | // grpc.WithBalancerName("pick_first"), // "pick_first" is the default, so this DialOption is not necessary. 43 | grpc.WithInsecure(), 44 | ) 45 | if err != nil { 46 | log.Fatalf("did not connect: %v", err) 47 | } 48 | defer pickfirstConn.Close() 49 | 50 | log.Println("==== Calling helloworld.Greeter/SayHello with pick_first ====") 51 | makeRPCs(pickfirstConn, 10) 52 | 53 | // Case 2: Use round_robin load-balancing policy to build connection 54 | roundrobinConn, err := grpc.Dial( 55 | fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName), // // "example:///lb.example.grpc.io" 56 | grpc.WithBalancerName("round_robin"), // This sets the initial balancing policy. 57 | grpc.WithInsecure(), 58 | ) 59 | if err != nil { 60 | log.Fatalf("did not connect: %v", err) 61 | } 62 | defer roundrobinConn.Close() 63 | 64 | log.Println("==== Calling helloworld.Greeter/SayHello with round_robin ====") 65 | makeRPCs(roundrobinConn, 10) 66 | } 67 | 68 | // Name resolver implementation 69 | 70 | type exampleResolverBuilder struct{} 71 | 72 | func (*exampleResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { 73 | r := &exampleResolver{ 74 | target: target, 75 | cc: cc, 76 | addrsStore: map[string][]string{ 77 | exampleServiceName: addrs, // "lb.example.grpc.io": "localhost:50051", "localhost:50052" 78 | }, 79 | } 80 | r.start() 81 | return r, nil 82 | } 83 | func (*exampleResolverBuilder) Scheme() string { return exampleScheme } // "example" 84 | 85 | type exampleResolver struct { 86 | target resolver.Target 87 | cc resolver.ClientConn 88 | addrsStore map[string][]string 89 | } 90 | 91 | func (r *exampleResolver) start() { 92 | addrStrs := r.addrsStore[r.target.Endpoint] 93 | addrs := make([]resolver.Address, len(addrStrs)) 94 | for i, s := range addrStrs { 95 | addrs[i] = resolver.Address{Addr: s} 96 | } 97 | r.cc.UpdateState(resolver.State{Addresses: addrs}) 98 | } 99 | func (*exampleResolver) ResolveNow(o resolver.ResolveNowOptions) {} 100 | func (*exampleResolver) Close() {} 101 | 102 | func init() { 103 | resolver.Register(&exampleResolverBuilder{}) 104 | } 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grpc-up-and-running 2 | 3 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 4 | 5 | The study note of the book "[gRPC: Up and Running (Kasun Indrasiri)](http://shop.oreilly.com/product/0636920282754.do)" and the reconstruction of source code. 6 | 7 | ![](imgs/book-cover.jpg) 8 | 9 | ## Study Notes 10 | - [Google Doc](https://docs.google.com/document/d/1-9X1T80fF26CSScx9xJNqLx5o1ruhYRGycqEnd9W5Gk/edit?usp=sharing) 11 | 12 | ## Experience 13 | - [**Install Protocol Buffer Compiler**](docs/install_protocol_buffer_compiler.md) 14 | - [**Generate Server Stub**](docs/generate_stub_go.md) 15 | - [**Build Executable File**](docs/build_executable.md) 16 | - [**Write Client Code**](docs/write_client.md) 17 | - [Implement Main Method](docs/write_client.md#implement-main-method) 18 | - [**Write Server Code**](docs/write_server.md) 19 | - [Implement Main Method](docs/write_server.md#implement-main-method) 20 | - [Implement Remote Methods](docs/write_server.md#implement-remote-methods) 21 | - [**Authentication**](docs/authentication.md) 22 | - [TLS Authentication](docs/authentication.md#tls-authentication) 23 | - [One-way TLS](docs/authentication.md#one-way-tls) 24 | - [Two-way TLS (mTLS)](#two-way-tls-mtls) 25 | - [Other Authentication Solutions](docs/authentication.md#other-authentication-solutions) 26 | - [Basic Authentication](docs/authentication.md#basic-authentication) 27 | - [OAuth 2.0](docs/authentication.md#oauth-20) 28 | - [JWT](docs/authentication.md#jwt) 29 | - [Google Token-Based Authentication](docs/authentication.md#google-token-based-authentication) 30 | - [**gRPC Gateway**](docs/grpc_gateway.md) 31 | 32 | ## Directory Structure 33 | - **docs**: The study notes of this books 34 | - diagram: The diagrams for this repository. 35 | - **examples**: The example code of gRPC sub-techniques. 36 | - loadbalancing: The load balancer for multiple gRPC services. 37 | - **security**: The example of the authentication solutions for gRPC. 38 | - one-way-tls: The one-way TLS authentication. 39 | - two-way-tls: The two-way (mTLS) authentication. 40 | - basic-auth: The basic authentication. 41 | - oauth2: The OAuth 2 authentication. 42 | - jwt: The JWT authentication. 43 | - grpc-gateway: The gRPC gateway example. 44 | - **imgs**: The images for this repository. 45 | - **productinfo**: The hello-world example of gRPC. 46 | - **ordermgt**: The gRPC examples for demostrating 4 gRPC communication patterns. 47 | 48 | ## Differences to The Original Source Code 49 | - Add the detailed [instruction](docs/install_protocol_buffer_compiler.md) about how to install protocol buffer compiler. 50 | - Add tutorials of writing server code and client code and modularize them by functionality. 51 | - Flatten the source code by chapter into one application. 52 | - Make sure the code is runnable (Fix some issues in the original source code). 53 | - Better documentation. 54 | - Add comments to make the code easy to read. 55 | 56 | ## Services And Remote Methods 57 | ### Product Info 58 | 59 | ![](docs/diagram/productinfo.png) 60 | 61 | | Method | Pattern | Description | 62 | |---|---|---| 63 | | AddProduct | Unary RPC | Add a product. | 64 | | GetProduct | Unary RPC | Get a product by product ID. | 65 | 66 | ### Order Management 67 | 68 | ![](docs/diagram/ordermgt.png) 69 | 70 | | Method | Pattern | Description | 71 | |---|---|---| 72 | | AddOrder | Unary RPC | Add a new order. | 73 | | GetOrder | Unary RPC | Get a order by order ID. | 74 | | SearchOrders | Server-side streaming | Get all the orders which has a certain item. | 75 | | UpdateOrders | Client-side streaming | Update multiple orders. | 76 | | ProcessOrders | Bidirectional streaming | Process multiple orders.
  • All the order IDs will be sent from client as a stream.
  • A combined shipment will contains all the orders which will be delivered to the same destination.
  • When the max batch size is reached, all the currently created combined shipments will be sent back to the client. | 77 | -------------------------------------------------------------------------------- /ordermgt/service/ecommerce/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | package google.protobuf; 39 | 40 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 41 | option cc_enable_arenas = true; 42 | option go_package = "github.com/golang/protobuf/ptypes/wrappers"; 43 | option java_package = "com.google.protobuf"; 44 | option java_outer_classname = "WrappersProto"; 45 | option java_multiple_files = true; 46 | option objc_class_prefix = "GPB"; 47 | 48 | // Wrapper message for `double`. 49 | // 50 | // The JSON representation for `DoubleValue` is JSON number. 51 | message DoubleValue { 52 | // The double value. 53 | double value = 1; 54 | } 55 | 56 | // Wrapper message for `float`. 57 | // 58 | // The JSON representation for `FloatValue` is JSON number. 59 | message FloatValue { 60 | // The float value. 61 | float value = 1; 62 | } 63 | 64 | // Wrapper message for `int64`. 65 | // 66 | // The JSON representation for `Int64Value` is JSON string. 67 | message Int64Value { 68 | // The int64 value. 69 | int64 value = 1; 70 | } 71 | 72 | // Wrapper message for `uint64`. 73 | // 74 | // The JSON representation for `UInt64Value` is JSON string. 75 | message UInt64Value { 76 | // The uint64 value. 77 | uint64 value = 1; 78 | } 79 | 80 | // Wrapper message for `int32`. 81 | // 82 | // The JSON representation for `Int32Value` is JSON number. 83 | message Int32Value { 84 | // The int32 value. 85 | int32 value = 1; 86 | } 87 | 88 | // Wrapper message for `uint32`. 89 | // 90 | // The JSON representation for `UInt32Value` is JSON number. 91 | message UInt32Value { 92 | // The uint32 value. 93 | uint32 value = 1; 94 | } 95 | 96 | // Wrapper message for `bool`. 97 | // 98 | // The JSON representation for `BoolValue` is JSON `true` and `false`. 99 | message BoolValue { 100 | // The bool value. 101 | bool value = 1; 102 | } 103 | 104 | // Wrapper message for `string`. 105 | // 106 | // The JSON representation for `StringValue` is JSON string. 107 | message StringValue { 108 | // The string value. 109 | string value = 1; 110 | } 111 | 112 | // Wrapper message for `bytes`. 113 | // 114 | // The JSON representation for `BytesValue` is JSON string. 115 | message BytesValue { 116 | // The bytes value. 117 | bytes value = 1; 118 | } -------------------------------------------------------------------------------- /docs/write_client.md: -------------------------------------------------------------------------------- 1 | # Write Client Code 2 | - [**Implement Main Method**](#implement-main-method) 3 | - [**Build Connection**](#build-connection) 4 | - [**Available Dial Option**](#available-dial-option) 5 | - [**Build Client**](#build-client) 6 | - [**Build Context**](#build-context) 7 | - [**Create Metadata (Optional)**](#create-metadata-optional) 8 | - [**Add Metadata to Context (Optional)**](#add-metadata-to-context-optional) 9 | - [**Call Remote Method**](#call-remote-method) 10 | - [**Handle Response Error**](#handle-response-error) 11 | - [**Read Metadata from Response**](#read-metadata-from-response) 12 | 13 | ## Implement Main Method 14 | ### Build Connection 15 | - Basic version 16 | ```go 17 | conn, err := grpc.Dial(address) 18 | ``` 19 | - With dial option(s) 20 | ```go 21 | opts := []grpc.DialOption{ 22 | opt1, opt2, opt3 23 | } 24 | conn, err := grpc.Dial(address, opts...) 25 | ``` 26 | 27 | ### Available Dial Option 28 | - Security 29 | - No security 30 | ```go 31 | grpc.WithInsecure() 32 | ``` 33 | - Interceptor 34 | - Unary interceptor 35 | ```go 36 | grpc.WithUnaryInterceptor(unaryInterceptorFunc) 37 | ``` 38 | - Stream interceptor 39 | ```go 40 | grpc.WithStreamInterceptor(streamInterceptorFunc) 41 | ``` 42 | 43 | ### Build Client 44 | - Basic version 45 | ```go 46 | client := pb.NewAbcClient(conn) // Abc is the service name 47 | ``` 48 | 49 | ### Build Context 50 | - With timeout 51 | ```go 52 | ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5) 53 | ``` 54 | - With deadline 55 | ```go 56 | deadline := time.Now().Add(time.Duration(5 * time.Second)) 57 | ctx, cancel := context.WithDeadline(context.Background(), deadline) 58 | ``` 59 | - With metadata 60 | ```go 61 | import "google.golang.org/grpc/metadata" 62 | ctx := metadata.NewOutgoingContext(context.Background(), md) 63 | ``` 64 | 65 | ### Create Metadata (Optional) 66 | - Option 1 67 | ```go 68 | md := metadata.New(map[string]string{"key1": "val1", "key2": "val2"}) 69 | ``` 70 | - Option 2 71 | ```go 72 | md := metadata.Pairs( 73 | "key1", "val1", 74 | "key2", "val2" 75 | ) 76 | ``` 77 | 78 | ### Add Metadata to Context (Optional) 79 | - Create a new context by metadata 80 | ```go 81 | ctx := metadata.NewOutgoingContext(context.Background(), md) 82 | ``` 83 | - Append metadata to an existing context 84 | ```go 85 | ctx2 := metadata.AppendToOutgoingContext(ctx1, "key1", "val1", "key2", "val2") 86 | ``` 87 | 88 | ### Call Remote Method 89 | - Unary 90 | ```go 91 | output, err = client.someRemoteFunc(ctx, &input) 92 | ``` 93 | - Server-side streaming 94 | ```go 95 | outputStream, streamErr := client.someRemoteFunc(ctx, input) 96 | 97 | for { // Process multiple outputs 98 | output, err := outputStream.Recv() 99 | if err == io.EOF { // End of stream, break infinite loop 100 | log.Print("EOF") 101 | break 102 | } 103 | 104 | if err == nil { 105 | // Process single output. 106 | } 107 | } 108 | ``` 109 | - Client-side streaming 110 | ```go 111 | inputStream, err := client.someRemoteFunc(ctx) // Create input stream 112 | 113 | for _ , input := range inputs { // Send multiple inputs 114 | if err := inputStream.Send(&input); err != nil { 115 | log.Fatalf("%v.Send(%v) = %v", inputStream, input, err) 116 | } 117 | } 118 | 119 | output, err := inputStream.CloseAndRecv() // Close sending and get output 120 | ``` 121 | 122 | ### Handle Response Error 123 | ```go 124 | import "google.golang.org/grpc/status" 125 | 126 | output, err = client.someRemoteFunc(ctx, &input) 127 | if err != nil { 128 | errorCode := status.Code(err) 129 | errorStatus := status.Convert(err) 130 | errorDetails := errorStatus.Details() 131 | 132 | // Error handling 133 | } 134 | ``` 135 | 136 | ### Read Metadata from Response 137 | - Unary 138 | ```go 139 | var header, trailer metadata.MD 140 | output, err = client.someRemoteFunc(ctx, &input, grpc.Header(&header), grpc.Trailer(&trailer)) 141 | // Process header and trailer map 142 | ``` 143 | - Streaming 144 | ```go 145 | outputStream, streamErr := client.someRemoteFunc(ctx, input) 146 | header, err := outputStream.Header() 147 | trailer := outputStream.Trailer() 148 | // Process header and trailer map 149 | ``` 150 | -------------------------------------------------------------------------------- /docs/write_server.md: -------------------------------------------------------------------------------- 1 | # Write Server Code 2 | 3 | - [**Implement Main Method**](#implement-main-method) 4 | - [**Build Listener**](#build-listener) 5 | - [**Build gRPC Server**](#build-grpc-server) 6 | - [**Available Server Option**](#available-server-option) 7 | - [**Register Service(s)**](#register-services) 8 | - [**Start gRPC Server**](#start-grpc-server) 9 | - [**Implement Remote Methods**](#implement-remote-methods) 10 | - [**Basic Pattern**](#basic-pattern) 11 | - [**Process Inputs**](#process-inputs) 12 | - [**Return Outputs**](#return-outputs) 13 | 14 | ## Implement Main Method 15 | ### Build Listener 16 | ```go 17 | listener, err := net.Listen("tcp", ":50051") 18 | ``` 19 | 20 | ### Build gRPC Server 21 | - Basic version 22 | ```go 23 | s := grpc.NewServer() 24 | ``` 25 | - With server option(s) 26 | ```go 27 | opts := []grpc.ServerOption{ 28 | opt1, opt2, opt3 29 | } 30 | s := grpc.NewServer(opts...) 31 | ``` 32 | 33 | ### Available Server Option 34 | - Unary interceptor 35 | ```go 36 | grpc.UnaryInterceptor(unaryInterceptorFunc) 37 | ``` 38 | - Stream interceptor 39 | ```go 40 | grpc.StreamInterceptor(streamInterceptorFunc) 41 | ``` 42 | 43 | ### Register Service(s) 44 | - Register single service 45 | ```go 46 | type abcServer struct {} 47 | 48 | pb.RegisterAbcServer(s, &abcServer{}) // Abc is the service name 49 | ``` 50 | - Register multiple services 51 | ```go 52 | type abcServer struct {} 53 | type xyzServer struct {} 54 | 55 | abc_pb.RegisterAbcServer(s, &abcServer{}) // Abc is the service name 56 | xyz_pb.RegisterXyzServer(s, &xyzServer{}) // Xyz is the service name 57 | ``` 58 | 59 | ### Start gRPC Server 60 | ```go 61 | if err := s.Serve(lis); err != nil { 62 | log.Fatalf("failed to serve: %v", err) 63 | } 64 | ``` 65 | 66 | ## Implement Remote Methods 67 | ### Basic Pattern 68 | ```go 69 | type abcServer struct {} 70 | 71 | func (s *abcServer) RemoteFunc1(ctx context.Context, input *InputType) (*OutputType, error) {} 72 | 73 | func (s *abcServer) RemoteFunc2(ctx context.Context, input *InputType) (*OutputType, error) {} 74 | 75 | func (s *abcServer) RemoteFunc3(ctx context.Context, input *InputType) (*OutputType, error) {} 76 | ``` 77 | 78 | ### Process Inputs 79 | - Process unary input 80 | ```go 81 | type abcServer struct {} 82 | 83 | func (s *abcServer) RemoteFunc(ctx context.Context, input *InputType) (*OutputType, error) { 84 | // Use input directly. 85 | } 86 | ``` 87 | - Process stream intput 88 | ```go 89 | type abcServer struct {} 90 | 91 | func (s *abcServer) RemoteFunc(stream pb.Abc_RemoteFuncServer) error { 92 | for { 93 | input, err := stream.Recv() 94 | if err == io.EOF { 95 | return stream.SendAndClose(output) // At the end of input stream, return the output. 96 | } 97 | 98 | if err != nil { 99 | return err 100 | } 101 | 102 | // Process single input. 103 | } 104 | } 105 | ``` 106 | - Process metadata 107 | - In unary input function 108 | ```go 109 | func (s *abcServer) RemoteFunc(ctx context.Context, input *InputType) (*OutputType, error) { 110 | md, ok := metadata.FromIncomingContext(ctx) 111 | } 112 | ``` 113 | - In stream input function 114 | ```go 115 | func (s *abcServer) RemoteFunc(stream pb.Abc_RemoteFuncServer) error { 116 | md, ok := metadata.FromIncomingContext(stream.Context()) 117 | } 118 | ``` 119 | 120 | ### Return Outputs 121 | - Return unary output 122 | ```go 123 | func (s *abcServer) RemoteFunc(ctx context.Context, input *InputType) (*OutputType, error) { 124 | return &output, status.New(codes.OK, "").Err() 125 | } 126 | ``` 127 | - Return stream output 128 | ```go 129 | func (s *abcServer) RemoteFunc(input *InputType, stream pb.Abc_RemoteFuncServer) error { 130 | for _ , output := range output { 131 | err := stream.Send(&output) 132 | } 133 | return nil 134 | } 135 | ``` 136 | - Return metadata 137 | - In unary input function 138 | ```go 139 | func (s *abcServer) RemoteFunc(ctx context.Context, input *InputType) (*OutputType, error) { 140 | header := metadata.Pairs("header-key", "val") 141 | grpc.SendHeader(ctx, header) 142 | trailer := metadata.Pairs("trailer-key", "val") 143 | grpc.SetTrailer(ctx, trailer) 144 | } 145 | ``` 146 | - In stream input function 147 | ```go 148 | func (s *abcServer) RemoteFunc(stream pb.Abc_RemoteFuncServer) error { 149 | header := metadata.Pairs("header-key", "val") 150 | stream.SendHeader(header) 151 | trailer := metadata.Pairs("trailer-key", "val") 152 | stream.SetTrailer(trailer) 153 | } 154 | ``` 155 | - Return error 156 | - Only error status 157 | ```go 158 | errorStatus := status.New(codes.ErrorCodeOption, "The error description.") // ErrorCodeOption needs to be replaced by real option. 159 | return errorStatus.Err() 160 | ``` 161 | - error status with details 162 | ```go 163 | import epb "google.golang.org/genproto/googleapis/rpc/errdetails" 164 | 165 | errorStatus := status.New(codes.ErrorCodeOption, "The error description.") // ErrorCodeOption needs to be replaced by real option. 166 | ds, err := errorStatus.WithDetails( 167 | &epb.DetailOption1{}, // DetailOption1 needs to be replaced by real option. 168 | &epb.DetailOption2{}, // DetailOption2 needs to be replaced by real option. 169 | &epb.DetailOption3{} // DetailOption3 needs to be replaced by real option. 170 | ) 171 | return ds.Err() 172 | ``` 173 | 174 | -------------------------------------------------------------------------------- /docs/grpc_gateway.md: -------------------------------------------------------------------------------- 1 | # gRPC Gateway 2 | 3 | - [**Background**](#background) 4 | - [**Installation**](#installation) 5 | - [**Modify The Service Definition File (.proto)**](#modify-the-service-definition-file-proto) 6 | - [**Generate Service Stub (.pb.go)**](#generate-service-stub-pbgo) 7 | - [**Generate Reverse Proxy (.pb.gw.go)**](#generate-reverse-proxy-pbgwgo) 8 | - [**Write gRPC Server Code**](#write-grpc-server-code) 9 | - [**Write Reverse-Proxy Server Code**](#write-reverse-proxy-server-code) 10 | - [**Build And Run gPRC Server and Reverse Proxy Server**](#build-and-run-gprc-server-and-reverse-proxy-server) 11 | - [**Verify**](#verify) 12 | 13 | ## Background 14 | ![](../docs/diagram/gateway.png) 15 | - Add a reverse proxy server in front of gRPC server to expose RESTful JSON API for each remote method in the gRPC service and accept HTTP requests from REST clients. 16 | - Provide the ability to invoke gRPC service in both gRPC and RESTful ways. 17 | - The gRPC Gateway project can be found in [here](https://github.com/grpc-ecosystem/grpc-gateway). 18 | 19 | ## Installation 20 | - Make sure the Protocol Buffer Compiler has been installed properly. 21 | - Download some dependent packages 22 | ```bash 23 | go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway 24 | go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger 25 | go get -u github.com/golang/protobuf/protoc-gen-go 26 | ``` 27 | 28 | ## Modify The Service Definition File (.proto) 29 | - Example 30 | ```proto 31 | syntax = "proto3"; 32 | 33 | import "google/protobuf/wrappers.proto"; 34 | import "google/api/annotations.proto"; 35 | 36 | package ecommerce; 37 | 38 | service ProductInfo { 39 | rpc addProduct(Product) returns (google.protobuf.StringValue) { 40 | option (google.api.http) = { 41 | post: "/v1/product" 42 | body: "*" 43 | }; 44 | } 45 | rpc getProduct(google.protobuf.StringValue) returns (Product) { 46 | option (google.api.http) = { 47 | get:"/v1/product/{value}" 48 | }; 49 | } 50 | } 51 | 52 | message Product { 53 | string id = 1; 54 | string name = 2; 55 | string description = 3; 56 | float price = 4; 57 | } 58 | ``` 59 | - Rules 60 | - Each mapping needs to specify a URL path template and an HTTP method. 61 | - The path template can contain one or more fields in the gRPC request message. But those fields should be nonrepeated fields with primitive types. 62 | - Any fields in the request message that are not in the path template automatically become HTTP query parameters if there is no HTTP request body. 63 | - Fields that are mapped to URL query parameters should be either a primitive type or a repeated primitive type or a nonrepeated message type. 64 | - For a repeated field type in query parameters, the parameter can be repeated in the URL. 65 | `...?param=A¶m=B.` 66 | - For a message type in query parameters, each field of the message is mapped to a separate parameter. 67 | `...?foo.a=A&foo.b=B&foo.c=C` 68 | 69 | ## Generate Service Stub (.pb.go) 70 | - Change directory to the base directory of the gRPC server (which has `main.go` for the gRPC server). 71 | - Run the command. 72 | ```bash 73 | protoc -I \ 74 | -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ 75 | --go_out=plugins=grpc: 76 | ``` 77 | - It will generate the service stub `*.pb.go` in the target directory. 78 | 79 | ## Generate Reverse Proxy (.pb.gw.go) 80 | - Change directory to the base directory of the reverse proxy server (which has `main.go` for the reverse proxy server). 81 | - Run the command. 82 | ```bash 83 | protoc -I \ 84 | -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ 85 | --grpc-gateway_out=logtostderr=true: 86 | ``` 87 | - It will generate the reverse proxy stub `*.pb.gw.go` in the target directory. 88 | - Copy the service stub (.pb.go) into the same directory of the reverse proxy stub (.pb.gw.go). 89 | 90 | ## Write gRPC Server Code 91 | - Just write the code of the gRPC server as before. No special code change for gRPC gateway. 92 | - The instruction can be found in [here](../docs/write_server.md). 93 | 94 | ## Write Reverse-Proxy Server Code 95 | - The following code will connect to the gRPC server by port 50051 and open HTTP endpoint at port 8081. 96 | ```go 97 | package main 98 | 99 | import ( 100 | "context" 101 | "log" 102 | "net/http" 103 | 104 | "github.com/grpc-ecosystem/grpc-gateway/runtime" 105 | "google.golang.org/grpc" 106 | 107 | gw "examples/grpc-gateway/reverse-proxy/ecommerce" 108 | ) 109 | 110 | var ( 111 | grpcServerEndpoint = "localhost:50051" 112 | reverseProxyPort = "8081" 113 | ) 114 | 115 | func main() { 116 | ctx := context.Background() 117 | ctx, cancel := context.WithCancel(ctx) 118 | defer cancel() 119 | 120 | mux := runtime.NewServeMux() 121 | opts := []grpc.DialOption{grpc.WithInsecure()} 122 | err := gw.RegisterProductInfoHandlerFromEndpoint(ctx, mux, grpcServerEndpoint, opts) 123 | 124 | if err != nil { 125 | log.Fatalf("Fail to register gRPC gateway server endpoint: %v", err) 126 | } 127 | 128 | log.Printf("Starting gRPC gateway server on port " + reverseProxyPort) 129 | if err := http.ListenAndServe(":" + reverseProxyPort, mux); err != nil { 130 | log.Fatalf("Could not setup HTTP endpoint: %v", err) 131 | } 132 | } 133 | ``` 134 | 135 | ## Build And Run gPRC Server and Reverse Proxy Server 136 | - No special logic to build the executable file for the reverse proxy server. 137 | - The instruction can be found in [here](../docs/build_executable.md). 138 | 139 | ## Verify 140 | - **Test 1** 141 | - Method: `POST` 142 | - URL: `http://localhost:8081/v1/product` 143 | - Body: 144 | ```json 145 | { 146 | "name": "Apple", 147 | "description": "iphone7", 148 | "price": 699 149 | } 150 | ``` 151 | - **Test 2** 152 | - Method: `GET` 153 | - URL: `http://localhost:8081/v1/product/f7e2bc30-e51a-4840-a45a-0c5b676f58d4` 154 | -------------------------------------------------------------------------------- /ordermgt/service/ordermgt_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "github.com/golang/protobuf/ptypes/wrappers" 7 | wrapper "github.com/golang/protobuf/ptypes/wrappers" 8 | epb "google.golang.org/genproto/googleapis/rpc/errdetails" 9 | "google.golang.org/grpc" 10 | "google.golang.org/grpc/codes" 11 | "google.golang.org/grpc/status" 12 | "io" 13 | "log" 14 | pb "ordergmt/service/ecommerce" 15 | "strings" 16 | "time" 17 | ) 18 | 19 | const ( 20 | maxBatchSize = 3 21 | ) 22 | 23 | var orderMap = make(map[string]pb.Order) 24 | 25 | type orderMgtServer struct { 26 | orderMap map[string]*pb.Order 27 | } 28 | 29 | // Add a new order. 30 | // Simple RPC 31 | func (s *orderMgtServer) AddOrder(ctx context.Context, orderReq *pb.Order) (*wrapper.StringValue, error) { 32 | if orderReq.Id == "-1" { 33 | log.Printf("Order ID is invalid! -> Received Order ID %s", orderReq.Id) 34 | 35 | errorStatus := status.New(codes.InvalidArgument, "Invalid information received") 36 | ds, err := errorStatus.WithDetails( 37 | &epb.BadRequest_FieldViolation{ 38 | Field:"ID", 39 | Description: fmt.Sprintf("Order ID received is not valid %s : %s", orderReq.Id, orderReq.Description), 40 | }, 41 | ) 42 | if err != nil { 43 | return nil, errorStatus.Err() 44 | } 45 | 46 | return nil, ds.Err() 47 | } else { 48 | log.Printf("Order Added. ID : %v", orderReq.Id) 49 | orderMap[orderReq.Id] = *orderReq 50 | return &wrapper.StringValue{Value: "Order Added: " + orderReq.Id}, nil 51 | } 52 | } 53 | 54 | // Get a order by order ID. 55 | // Simple RPC 56 | func (s *orderMgtServer) GetOrder(ctx context.Context, orderId *wrapper.StringValue) (*pb.Order, error) { 57 | ord, exists := orderMap[orderId.Value] 58 | if exists { 59 | return &ord, status.New(codes.OK, "").Err() 60 | } 61 | 62 | return nil, status.Errorf(codes.NotFound, "Order does not exist. : ", orderId) 63 | } 64 | 65 | // Get all the orders which has a certain item. 66 | // All the matched orders will be returned from orderMgtServer as a stream. 67 | // Server-side Streaming RPC 68 | func (s *orderMgtServer) SearchOrders(searchQuery *wrappers.StringValue, stream pb.OrderManagement_SearchOrdersServer) error { 69 | for key, order := range orderMap { 70 | log.Print(key, order) 71 | for _, itemStr := range order.Items { 72 | log.Print(itemStr) 73 | if strings.Contains(itemStr, searchQuery.Value) { 74 | // Send the matching orders in a stream 75 | err := stream.Send(&order) 76 | if err != nil { 77 | return fmt.Errorf("error sending message to stream : %v", err) 78 | } 79 | log.Print("Matching Order Found : " + key) 80 | break 81 | } 82 | } 83 | } 84 | return nil 85 | } 86 | 87 | // Update multiple orders. 88 | // All the orders will be sent from client as a stream. 89 | // Client-side Streaming RPC 90 | func (s *orderMgtServer) UpdateOrders(stream pb.OrderManagement_UpdateOrdersServer) error { 91 | ordersStr := "Updated Order IDs : " 92 | for { 93 | order, err := stream.Recv() 94 | if err == io.EOF { 95 | // Finished reading the order stream. 96 | return stream.SendAndClose(&wrapper.StringValue{Value: "Orders processed " + ordersStr}) 97 | } 98 | 99 | if err != nil { 100 | return err 101 | } 102 | // Update order 103 | orderMap[order.Id] = *order 104 | 105 | log.Printf("Order ID : %s - %s", order.Id, "Updated") 106 | ordersStr += order.Id + ", " 107 | } 108 | } 109 | 110 | // Process multiple orders 111 | // All the order IDs will be sent from client as a stream. 112 | // A combined shipment will contains all the orders which will be delivered to the same destination. 113 | // When the max batch size is reached, all the currently created combined shipments will be sent back to the client. 114 | // Bi-directional Streaming RPC 115 | func (s *orderMgtServer) ProcessOrders(stream pb.OrderManagement_ProcessOrdersServer) error { 116 | currentBatchSize := 1 117 | var combinedShipmentMap = make(map[string]pb.CombinedShipment) 118 | for { 119 | orderId, err := stream.Recv() 120 | log.Printf("Reading Proc order : %s", orderId) 121 | if err == io.EOF { 122 | // If the stream reached the end (EOF is the signal for the end of the stream) 123 | // Return all the remaining combined shipments to client. 124 | log.Printf("EOF : %s", orderId) 125 | for _, shipment := range combinedShipmentMap { 126 | if err := stream.Send(&shipment); err != nil { 127 | return err 128 | } 129 | } 130 | return nil 131 | } 132 | if err != nil { 133 | log.Println(err) 134 | return err 135 | } 136 | 137 | destination := orderMap[orderId.GetValue()].Destination 138 | shipment, found := combinedShipmentMap[destination] 139 | 140 | if found { 141 | // If the combined shipment has been found for that order by the same destination, 142 | // Append the order into the combined shipment. 143 | ord := orderMap[orderId.GetValue()] 144 | shipment.OrdersList = append(shipment.OrdersList, &ord) 145 | combinedShipmentMap[destination] = shipment 146 | } else { 147 | // If the combined shipment hasn't been found for that order by the same destination, 148 | // Create a new combined shipment, append the order into it. 149 | comShip := pb.CombinedShipment{Id: "cmb - " + (orderMap[orderId.GetValue()].Destination), Status: "Processed!", } 150 | ord := orderMap[orderId.GetValue()] 151 | comShip.OrdersList = append(shipment.OrdersList, &ord) 152 | combinedShipmentMap[destination] = comShip 153 | log.Print(len(comShip.OrdersList), comShip.GetId()) 154 | } 155 | 156 | if currentBatchSize == maxBatchSize { 157 | // If the current batch size reaches the max batch size, 158 | // return all the combined shipments to client. 159 | for _, comb := range combinedShipmentMap { 160 | log.Printf("Shipping : %v -> %v" , comb.Id, len(comb.OrdersList)) 161 | if err := stream.Send(&comb); err != nil { 162 | return err 163 | } 164 | } 165 | currentBatchSize = 0 166 | combinedShipmentMap = make(map[string]pb.CombinedShipment) 167 | } else { 168 | currentBatchSize++ 169 | } 170 | } 171 | } 172 | 173 | // Unary Interceptor (orderMgtServer-side) 174 | // This interceptor consists of pre-processing logic which will be executed before running the remote method, 175 | // post-processing logic which will be executed after running the remote method. 176 | func orderUnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { 177 | // Pre-processing phase 178 | // Gets info about the current RPC call by examining the args passed in 179 | log.Println("======= [Server Interceptor] ", info.FullMethod) 180 | log.Printf(" Pre Proc Message : %s", req) 181 | 182 | // Invoking the handler to complete the normal execution of a unary RPC. 183 | m, err := handler(ctx, req) 184 | 185 | // Post-processing phase 186 | log.Printf(" Post Proc Message : %s", m) 187 | return m, err 188 | } 189 | 190 | // wrappedStream wraps grpc.ServerStream and intercepts the RecvMsg and SendMsg method call. 191 | type wrappedStream struct { 192 | grpc.ServerStream 193 | } 194 | 195 | // Implementing the RecvMsg function of the wrapper to process messages received with stream RPC. 196 | func (w *wrappedStream) RecvMsg(m interface{}) error { 197 | log.Printf("====== [Server Stream Interceptor Wrapper] Receive a message (Type: %T) at %s", m, time.Now().Format(time.RFC3339)) 198 | return w.ServerStream.RecvMsg(m) 199 | } 200 | 201 | // Implementing the SendMsg function of the wrapper to process messages sent with stream RPC. 202 | func (w *wrappedStream) SendMsg(m interface{}) error { 203 | log.Printf("====== [Server Stream Interceptor Wrapper] Send a message (Type: %T) at %v", m, time.Now().Format(time.RFC3339)) 204 | return w.ServerStream.SendMsg(m) 205 | } 206 | 207 | // Creating an instance of the new wrapper stream. 208 | func newWrappedStream(s grpc.ServerStream) grpc.ServerStream { 209 | return &wrappedStream{s} 210 | } 211 | 212 | // Streaming interceptor implementation. 213 | func orderServerStreamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { 214 | // Pre-processing phase 215 | log.Println("====== [Server Stream Interceptor] ", info.FullMethod) 216 | 217 | // Invoking the StreamHandler to complete the execution of RPC invocation 218 | err := handler(srv, newWrappedStream(ss)) 219 | if err != nil { 220 | log.Printf("RPC failed with error %v", err) 221 | } 222 | return err 223 | } -------------------------------------------------------------------------------- /ordermgt/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | wrapper "github.com/golang/protobuf/ptypes/wrappers" 6 | epb "google.golang.org/genproto/googleapis/rpc/errdetails" 7 | "google.golang.org/grpc" 8 | "google.golang.org/grpc/codes" 9 | hwpb "google.golang.org/grpc/examples/helloworld/helloworld" 10 | "google.golang.org/grpc/status" 11 | "io" 12 | "log" 13 | pb "ordergmt/client/ecommerce" 14 | "time" 15 | ) 16 | 17 | const ( 18 | address = "localhost:50051" 19 | ) 20 | 21 | func main() { 22 | // Setting up a connection to the server. 23 | conn, err := grpc.Dial(address, grpc.WithInsecure(), 24 | grpc.WithUnaryInterceptor(orderUnaryClientInterceptor), // Register unary interceptor. 25 | grpc.WithStreamInterceptor(clientStreamInterceptor)) // Register stream interceptor. 26 | if err != nil { 27 | log.Fatalf("did not connect: %v", err) 28 | } 29 | defer conn.Close() 30 | 31 | // Create 2 clients for different services running on the same server. 32 | orderMgtClient := pb.NewOrderManagementClient(conn) 33 | helloClient := hwpb.NewGreeterClient(conn) 34 | 35 | // Initialize context with timeout 36 | ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5) 37 | 38 | // Initialize context with deadline 39 | //clientDeadline := time.Now().Add(time.Duration(2 * time.Second)) 40 | //ctx, cancel := context.WithDeadline(context.Background(), clientDeadline) 41 | 42 | defer cancel() 43 | 44 | // ========================================= 45 | // Add Order 46 | // ========================================= 47 | // Case 1: Add an order with valid ID 48 | order1 := pb.Order{Id: "101", Items: []string{"iPhone XS", "Mac Book Pro"}, Destination: "San Jose, CA", Price: 2300.00} 49 | res, _ := orderMgtClient.AddOrder(ctx, &order1) 50 | if res != nil { 51 | log.Print("AddOrder Response -> ", res.Value) 52 | } 53 | 54 | // Case 2: Add an order with invalid ID 55 | order2 := pb.Order{Id: "-1", Items:[]string{"iPhone XS", "Mac Book Pro"}, Destination:"San Jose, CA", Price:2300.00} 56 | res, addOrderError := orderMgtClient.AddOrder(ctx, &order2) 57 | 58 | if addOrderError != nil { 59 | errorCode := status.Code(addOrderError) 60 | if errorCode == codes.InvalidArgument { 61 | log.Printf("Invalid Argument Error : %s", errorCode) 62 | errorStatus := status.Convert(addOrderError) 63 | for _, d := range errorStatus.Details() { 64 | switch info := d.(type) { 65 | case *epb.BadRequest_FieldViolation: 66 | log.Printf("Request Field Invalid: %s", info) 67 | default: 68 | log.Printf("Unexpected error type: %s", info) 69 | } 70 | } 71 | } else { 72 | log.Printf("Unhandled error : %s ", errorCode) 73 | } 74 | } else { 75 | log.Print("AddOrder Response -> ", res.Value) 76 | } 77 | 78 | // ========================================= 79 | // Get Order 80 | // ========================================= 81 | retrievedOrder , err := orderMgtClient.GetOrder(ctx, &wrapper.StringValue{Value: "106"}) 82 | log.Print("GetOrder Response -> : ", retrievedOrder) 83 | 84 | // ========================================= 85 | // Search Order : Server streaming scenario 86 | // ========================================= 87 | searchStream, _ := orderMgtClient.SearchOrders(ctx, &wrapper.StringValue{Value: "Google"}) 88 | for { 89 | searchOrder, err := searchStream.Recv() 90 | if err == io.EOF { 91 | log.Print("EOF") 92 | break 93 | } 94 | 95 | if err == nil { 96 | log.Print("Search Result : ", searchOrder) 97 | } 98 | } 99 | 100 | // ========================================= 101 | // Update Orders : Client streaming scenario 102 | // ========================================= 103 | updOrder1 := pb.Order{Id: "102", Items:[]string{"Google Pixel 3A", "Google Pixel Book"}, Destination:"Mountain View, CA", Price:1100.00} 104 | updOrder2 := pb.Order{Id: "103", Items:[]string{"Apple Watch S4", "Mac Book Pro", "iPad Pro"}, Destination:"San Jose, CA", Price:2800.00} 105 | updOrder3 := pb.Order{Id: "104", Items:[]string{"Google Home Mini", "Google Nest Hub", "iPad Mini"}, Destination:"Mountain View, CA", Price:2200.00} 106 | 107 | updateStream, err := orderMgtClient.UpdateOrders(ctx) 108 | 109 | if err != nil { 110 | log.Fatalf("%v.UpdateOrders(_) = _, %v", orderMgtClient, err) 111 | } 112 | 113 | // Updating order 1 114 | if err := updateStream.Send(&updOrder1); err != nil { 115 | log.Fatalf("%v.Send(%v) = %v", updateStream, updOrder1, err) 116 | } 117 | 118 | // Updating order 2 119 | if err := updateStream.Send(&updOrder2); err != nil { 120 | log.Fatalf("%v.Send(%v) = %v", updateStream, updOrder2, err) 121 | } 122 | 123 | // Updating order 3 124 | if err := updateStream.Send(&updOrder3); err != nil { 125 | log.Fatalf("%v.Send(%v) = %v", updateStream, updOrder3, err) 126 | } 127 | 128 | updateRes, err := updateStream.CloseAndRecv() 129 | if err != nil { 130 | log.Fatalf("%v.CloseAndRecv() got error %v, want %v", updateStream, err, nil) 131 | } 132 | log.Printf("Update Orders Res : %s", updateRes) 133 | 134 | // ========================================= 135 | // Process Order : Bi-di streaming scenario 136 | // ========================================= 137 | streamProcOrder, err := orderMgtClient.ProcessOrders(ctx) 138 | if err != nil { 139 | log.Fatalf("%v.ProcessOrders(_) = _, %v", orderMgtClient, err) 140 | } 141 | 142 | if err := streamProcOrder.Send(&wrapper.StringValue{Value:"102"}); err != nil { 143 | log.Fatalf("%v.Send(%v) = %v", orderMgtClient, "102", err) 144 | } 145 | 146 | if err := streamProcOrder.Send(&wrapper.StringValue{Value:"103"}); err != nil { 147 | log.Fatalf("%v.Send(%v) = %v", orderMgtClient, "103", err) 148 | } 149 | 150 | if err := streamProcOrder.Send(&wrapper.StringValue{Value:"104"}); err != nil { 151 | log.Fatalf("%v.Send(%v) = %v", orderMgtClient, "104", err) 152 | } 153 | 154 | channel := make(chan struct{}) 155 | go asncClientBidirectionalRPC(streamProcOrder, channel) 156 | time.Sleep(time.Millisecond * 1000) 157 | 158 | if err := streamProcOrder.Send(&wrapper.StringValue{Value:"101"}); err != nil { 159 | log.Fatalf("%v.Send(%v) = %v", orderMgtClient, "101", err) 160 | } 161 | if err := streamProcOrder.CloseSend(); err != nil { 162 | log.Fatal(err) 163 | } 164 | <- channel 165 | 166 | // ========================================= 167 | // SayHello : Call another service running on the same server 168 | // ========================================= 169 | hwCtx, cancel := context.WithTimeout(context.Background(), time.Second * 5) 170 | helloResponse, err := helloClient.SayHello(hwCtx, &hwpb.HelloRequest{Name: "gRPC Up and Running!"}) 171 | log.Print("Hello world response: ", helloResponse.Message) 172 | } 173 | 174 | func asncClientBidirectionalRPC(streamProcOrder pb.OrderManagement_ProcessOrdersClient, c chan struct{}) { 175 | for { 176 | combinedShipment, errProcOrder := streamProcOrder.Recv() 177 | if errProcOrder == io.EOF { 178 | break 179 | } 180 | log.Printf("Combined shipment : ", combinedShipment.OrdersList) 181 | } 182 | <-c 183 | } 184 | 185 | // Unary Interceptor (client-side) 186 | func orderUnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { 187 | // Pre-processing phase 188 | log.Println("Method : " + method) 189 | 190 | // Invoking the remote method 191 | err := invoker(ctx, method, req, reply, cc, opts...) 192 | 193 | // Post-processing phase 194 | log.Println(reply) 195 | 196 | return err 197 | } 198 | 199 | // wrappedStream wraps grpc.ClientStream and intercepts the RecvMsg and SendMsg method call. 200 | type wrappedStream struct { 201 | grpc.ClientStream 202 | } 203 | 204 | func (w *wrappedStream) RecvMsg(m interface{}) error { 205 | log.Printf("====== [Client Stream Interceptor] Receive a message (Type: %T) at %v", m, time.Now().Format(time.RFC3339)) 206 | return w.ClientStream.RecvMsg(m) 207 | } 208 | 209 | func (w *wrappedStream) SendMsg(m interface{}) error { 210 | log.Printf("====== [Client Stream Interceptor] Send a message (Type: %T) at %v", m, time.Now().Format(time.RFC3339)) 211 | return w.ClientStream.SendMsg(m) 212 | } 213 | 214 | // Creating an instance of the new wrapper stream. 215 | func newWrappedStream(s grpc.ClientStream) grpc.ClientStream { 216 | return &wrappedStream{s} 217 | } 218 | 219 | // Streaming interceptor implementation. 220 | func clientStreamInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { 221 | // Pre-processing phase 222 | log.Println("======= [Client Interceptor] ", method) 223 | 224 | // Invoking the Streamer to complete the execution of RPC invocation 225 | s, err := streamer(ctx, desc, cc, method, opts...) 226 | if err != nil { 227 | return nil, err 228 | } 229 | return newWrappedStream(s), nil 230 | } -------------------------------------------------------------------------------- /productinfo/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /productinfo/service/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/grpc-gateway/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo server. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo server. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/jwt/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/oauth2/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/oauth2/server/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/basic-auth/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/basic-auth/server/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/client/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | -------------------------------------------------------------------------------- /examples/security/one-way-tls/server/ecommerce/product_info.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: product_info.proto 3 | 4 | package ecommerce 5 | 6 | import ( 7 | context "context" 8 | fmt "fmt" 9 | proto "github.com/golang/protobuf/proto" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | math "math" 14 | ) 15 | 16 | // Reference imports to suppress errors if they are not otherwise used. 17 | var _ = proto.Marshal 18 | var _ = fmt.Errorf 19 | var _ = math.Inf 20 | 21 | // This is a compile-time assertion to ensure that this generated file 22 | // is compatible with the proto package it is being compiled against. 23 | // A compilation error at this line likely means your copy of the 24 | // proto package needs to be updated. 25 | const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 26 | 27 | type Product struct { 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` 30 | Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` 31 | Price float32 `protobuf:"fixed32,4,opt,name=price,proto3" json:"price,omitempty"` 32 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 33 | XXX_unrecognized []byte `json:"-"` 34 | XXX_sizecache int32 `json:"-"` 35 | } 36 | 37 | func (m *Product) Reset() { *m = Product{} } 38 | func (m *Product) String() string { return proto.CompactTextString(m) } 39 | func (*Product) ProtoMessage() {} 40 | func (*Product) Descriptor() ([]byte, []int) { 41 | return fileDescriptor_9a4d768ec9cb4951, []int{0} 42 | } 43 | 44 | func (m *Product) XXX_Unmarshal(b []byte) error { 45 | return xxx_messageInfo_Product.Unmarshal(m, b) 46 | } 47 | func (m *Product) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 48 | return xxx_messageInfo_Product.Marshal(b, m, deterministic) 49 | } 50 | func (m *Product) XXX_Merge(src proto.Message) { 51 | xxx_messageInfo_Product.Merge(m, src) 52 | } 53 | func (m *Product) XXX_Size() int { 54 | return xxx_messageInfo_Product.Size(m) 55 | } 56 | func (m *Product) XXX_DiscardUnknown() { 57 | xxx_messageInfo_Product.DiscardUnknown(m) 58 | } 59 | 60 | var xxx_messageInfo_Product proto.InternalMessageInfo 61 | 62 | func (m *Product) GetId() string { 63 | if m != nil { 64 | return m.Id 65 | } 66 | return "" 67 | } 68 | 69 | func (m *Product) GetName() string { 70 | if m != nil { 71 | return m.Name 72 | } 73 | return "" 74 | } 75 | 76 | func (m *Product) GetDescription() string { 77 | if m != nil { 78 | return m.Description 79 | } 80 | return "" 81 | } 82 | 83 | func (m *Product) GetPrice() float32 { 84 | if m != nil { 85 | return m.Price 86 | } 87 | return 0 88 | } 89 | 90 | type ProductID struct { 91 | Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 92 | XXX_NoUnkeyedLiteral struct{} `json:"-"` 93 | XXX_unrecognized []byte `json:"-"` 94 | XXX_sizecache int32 `json:"-"` 95 | } 96 | 97 | func (m *ProductID) Reset() { *m = ProductID{} } 98 | func (m *ProductID) String() string { return proto.CompactTextString(m) } 99 | func (*ProductID) ProtoMessage() {} 100 | func (*ProductID) Descriptor() ([]byte, []int) { 101 | return fileDescriptor_9a4d768ec9cb4951, []int{1} 102 | } 103 | 104 | func (m *ProductID) XXX_Unmarshal(b []byte) error { 105 | return xxx_messageInfo_ProductID.Unmarshal(m, b) 106 | } 107 | func (m *ProductID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 108 | return xxx_messageInfo_ProductID.Marshal(b, m, deterministic) 109 | } 110 | func (m *ProductID) XXX_Merge(src proto.Message) { 111 | xxx_messageInfo_ProductID.Merge(m, src) 112 | } 113 | func (m *ProductID) XXX_Size() int { 114 | return xxx_messageInfo_ProductID.Size(m) 115 | } 116 | func (m *ProductID) XXX_DiscardUnknown() { 117 | xxx_messageInfo_ProductID.DiscardUnknown(m) 118 | } 119 | 120 | var xxx_messageInfo_ProductID proto.InternalMessageInfo 121 | 122 | func (m *ProductID) GetValue() string { 123 | if m != nil { 124 | return m.Value 125 | } 126 | return "" 127 | } 128 | 129 | func init() { 130 | proto.RegisterType((*Product)(nil), "ecommerce.Product") 131 | proto.RegisterType((*ProductID)(nil), "ecommerce.ProductID") 132 | } 133 | 134 | func init() { proto.RegisterFile("product_info.proto", fileDescriptor_9a4d768ec9cb4951) } 135 | 136 | var fileDescriptor_9a4d768ec9cb4951 = []byte{ 137 | // 199 bytes of a gzipped FileDescriptorProto 138 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x4f, 139 | 0x29, 0x4d, 0x2e, 0x89, 0xcf, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 140 | 0x4c, 0x4d, 0xce, 0xcf, 0xcd, 0x4d, 0x2d, 0x4a, 0x4e, 0x55, 0x4a, 0xe5, 0x62, 0x0f, 0x80, 0x28, 141 | 0x10, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x62, 0xca, 0x4c, 142 | 0x11, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x02, 0x8b, 0x80, 0xd9, 0x42, 0x0a, 143 | 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x12, 0xcc, 0x60, 144 | 0x29, 0x64, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0x82, 0xa2, 0xcc, 0xe4, 0x54, 0x09, 0x16, 0x05, 0x46, 145 | 0x0d, 0xa6, 0x20, 0x08, 0x47, 0x49, 0x91, 0x8b, 0x13, 0x6a, 0x8d, 0xa7, 0x0b, 0x48, 0x49, 0x59, 146 | 0x62, 0x4e, 0x69, 0x2a, 0xd4, 0x2e, 0x08, 0xc7, 0xa8, 0x96, 0x8b, 0x1b, 0xa6, 0x24, 0x2f, 0x2d, 147 | 0x5f, 0xc8, 0x8c, 0x8b, 0x2b, 0x31, 0x25, 0x05, 0xe6, 0x36, 0x21, 0x3d, 0xb8, 0x93, 0xf5, 0xa0, 148 | 0x62, 0x52, 0x22, 0x98, 0x62, 0x9e, 0x2e, 0x20, 0x7d, 0xe9, 0xa9, 0x25, 0x30, 0x7d, 0x58, 0xd5, 149 | 0x48, 0x61, 0x31, 0x2d, 0x89, 0x0d, 0x1c, 0x34, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 150 | 0x1f, 0xc5, 0x58, 0x30, 0x01, 0x00, 0x00, 151 | } 152 | 153 | // Reference imports to suppress errors if they are not otherwise used. 154 | var _ context.Context 155 | var _ grpc.ClientConnInterface 156 | 157 | // This is a compile-time assertion to ensure that this generated file 158 | // is compatible with the grpc package it is being compiled against. 159 | const _ = grpc.SupportPackageIsVersion6 160 | 161 | // ProductInfoClient is the client API for ProductInfo service. 162 | // 163 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 164 | type ProductInfoClient interface { 165 | AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) 166 | GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) 167 | } 168 | 169 | type productInfoClient struct { 170 | cc grpc.ClientConnInterface 171 | } 172 | 173 | func NewProductInfoClient(cc grpc.ClientConnInterface) ProductInfoClient { 174 | return &productInfoClient{cc} 175 | } 176 | 177 | func (c *productInfoClient) AddProduct(ctx context.Context, in *Product, opts ...grpc.CallOption) (*ProductID, error) { 178 | out := new(ProductID) 179 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/addProduct", in, out, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return out, nil 184 | } 185 | 186 | func (c *productInfoClient) GetProduct(ctx context.Context, in *ProductID, opts ...grpc.CallOption) (*Product, error) { 187 | out := new(Product) 188 | err := c.cc.Invoke(ctx, "/ecommerce.ProductInfo/getProduct", in, out, opts...) 189 | if err != nil { 190 | return nil, err 191 | } 192 | return out, nil 193 | } 194 | 195 | // ProductInfoServer is the server API for ProductInfo service. 196 | type ProductInfoServer interface { 197 | AddProduct(context.Context, *Product) (*ProductID, error) 198 | GetProduct(context.Context, *ProductID) (*Product, error) 199 | } 200 | 201 | // UnimplementedProductInfoServer can be embedded to have forward compatible implementations. 202 | type UnimplementedProductInfoServer struct { 203 | } 204 | 205 | func (*UnimplementedProductInfoServer) AddProduct(ctx context.Context, req *Product) (*ProductID, error) { 206 | return nil, status.Errorf(codes.Unimplemented, "method AddProduct not implemented") 207 | } 208 | func (*UnimplementedProductInfoServer) GetProduct(ctx context.Context, req *ProductID) (*Product, error) { 209 | return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") 210 | } 211 | 212 | func RegisterProductInfoServer(s *grpc.Server, srv ProductInfoServer) { 213 | s.RegisterService(&_ProductInfo_serviceDesc, srv) 214 | } 215 | 216 | func _ProductInfo_AddProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 217 | in := new(Product) 218 | if err := dec(in); err != nil { 219 | return nil, err 220 | } 221 | if interceptor == nil { 222 | return srv.(ProductInfoServer).AddProduct(ctx, in) 223 | } 224 | info := &grpc.UnaryServerInfo{ 225 | Server: srv, 226 | FullMethod: "/ecommerce.ProductInfo/AddProduct", 227 | } 228 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 229 | return srv.(ProductInfoServer).AddProduct(ctx, req.(*Product)) 230 | } 231 | return interceptor(ctx, in, info, handler) 232 | } 233 | 234 | func _ProductInfo_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 235 | in := new(ProductID) 236 | if err := dec(in); err != nil { 237 | return nil, err 238 | } 239 | if interceptor == nil { 240 | return srv.(ProductInfoServer).GetProduct(ctx, in) 241 | } 242 | info := &grpc.UnaryServerInfo{ 243 | Server: srv, 244 | FullMethod: "/ecommerce.ProductInfo/GetProduct", 245 | } 246 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 247 | return srv.(ProductInfoServer).GetProduct(ctx, req.(*ProductID)) 248 | } 249 | return interceptor(ctx, in, info, handler) 250 | } 251 | 252 | var _ProductInfo_serviceDesc = grpc.ServiceDesc{ 253 | ServiceName: "ecommerce.ProductInfo", 254 | HandlerType: (*ProductInfoServer)(nil), 255 | Methods: []grpc.MethodDesc{ 256 | { 257 | MethodName: "addProduct", 258 | Handler: _ProductInfo_AddProduct_Handler, 259 | }, 260 | { 261 | MethodName: "getProduct", 262 | Handler: _ProductInfo_GetProduct_Handler, 263 | }, 264 | }, 265 | Streams: []grpc.StreamDesc{}, 266 | Metadata: "product_info.proto", 267 | } 268 | --------------------------------------------------------------------------------