GithubHelp home page GithubHelp logo

gogo / grpc-example Goto Github PK

View Code? Open in Web Editor NEW
456.0 13.0 87.0 19.33 MB

An example of using Go gRPC and tools from the greater gRPC ecosystem together with the GoGo Protobuf Project.

License: Other

Go 87.94% Makefile 12.06%
protobuf golang grpc grpc-gateway gogo-protobuf openapi-ui

grpc-example's Introduction

gRPC-Example

Build Status

This repo is an example of using Go gRPC and tools from the greater gRPC ecosystem together with the GoGo Protobuf Project.

OpenAPI UI in action

Installation

$ go get -u github.com/gogo/grpc-example

Running it

$ grpc-example
INFO: Serving gRPC on https://localhost:10000
INFO: parsed scheme: "passthrough"
INFO: ccResolverWrapper: sending new addresses to cc: [{localhost:10000 0  <nil>}]
INFO: ClientConn switching balancer to "pick_first"
INFO: pickfirstBalancer: HandleSubConnStateChange: 0xc420097cd0, CONNECTING
INFO: pickfirstBalancer: HandleSubConnStateChange: 0xc420097cd0, READY
INFO: Serving gRPC-Gateway on https://localhost:11000
INFO: Serving OpenAPI Documentation on https://localhost:11000/openapi-ui/

After starting the server, you can access the OpenAPI UI on https://localhost:11000/openapi-ui/

Development

To regenerate the proto files, ensure you have installed the generate dependencies:

$ GO111MODULE=on make install
go get \
        github.com/gogo/protobuf/protoc-gen-gogo \
        github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
        github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
        github.com/mwitkow/go-proto-validators/protoc-gen-govalidators \
        github.com/rakyll/statik
go: finding github.com/mwitkow/go-proto-validators/protoc-gen-govalidators latest
go: finding github.com/mwitkow/go-proto-validators latest
go: finding github.com/gogo/protobuf/protoc-gen-gogo latest
go: finding github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger latest
go: finding github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway latest

It also requires you to have the Google Protobuf compiler protoc installed. Please follow instructions for your platform on the official protoc repo.

Regenerate the files by running make generate:

$ make generate
# Generate gogo, gRPC-Gateway, swagger, go-validators output.
#
# -I declares import folders, in order of importance
# This is how proto resolves the protofile imports.
# It will check for the protofile relative to each of these
# folders and use the first one it finds.
#
# --gogo_out generates GoGo Protobuf output with gRPC plugin enabled.
# --grpc-gateway_out generates gRPC-Gateway output.
# --swagger_out generates an OpenAPI 2.0 specification for our gRPC-Gateway endpoints.
# --govalidators_out generates Go validation files for our messages types, if specified.
#
# The lines starting with Mgoogle/... are proto import replacements,
# which cause the generated file to import the specified packages
# instead of the go_package's declared by the imported protof files.
#
# $GOPATH/src is the output directory. It is relative to the GOPATH/src directory
# since we've specified a go_package option relative to that directory.
#
# proto/example.proto is the location of the protofile we use.
protoc \
        -I proto \
        -I vendor/github.com/grpc-ecosystem/grpc-gateway/ \
        -I vendor/github.com/gogo/googleapis/ \
        -I vendor/ \
        --gogo_out=plugins=grpc,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
        --grpc-gateway_out=allow_patch_feature=false,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
        --swagger_out=third_party/OpenAPI/ \
        --govalidators_out=gogoimport=true,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src \
        proto/example.proto
# Workaround for https://github.com/grpc-ecosystem/grpc-gateway/issues/229.
sed -i.bak "s/empty.Empty/types.Empty/g" proto/example.pb.gw.go && rm proto/example.pb.gw.go.bak
# Generate static assets for OpenAPI UI
statik -m -f -src third_party/OpenAPI/

grpc-example's People

Contributors

davidklassen avatar johanbrandhorst avatar mikluko avatar

Stargazers

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

Watchers

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

grpc-example's Issues

How is the OpenAPI UI generated?

I see a number of static assets added in a6e1cf3, but no indication where they came from. The option --swagger_out=third_party/OpenAPI/ to protoc only generates the JSON file. If I want to serve swagger UI from my application, how would I go about generating them? I don't want to just copy them from this repo.

I'm happy to create a PR with example/explanation if you point me in the right direction.

error occurred

I made following error while running the 'make generate' instruction thank's for you helper

google/protobuf/empty.proto: File not found.
google/protobuf/timestamp.proto: File not found.
google/protobuf/duration.proto: File not found.
google/protobuf/field_mask.proto: File not found.
google/protobuf/descriptor.proto: File not found.
google/api/annotations.proto:20:1: Import "google/protobuf/descriptor.proto" was not found or had errors.
google/api/annotations.proto:28:8: "google.protobuf.MethodOptions" is not defined.
google/protobuf/any.proto: File not found.
protoc-gen-swagger/options/openapiv2.proto:7:1: Import "google/protobuf/any.proto" was not found or had errors.
protoc-gen-swagger/options/openapiv2.proto:141:3: "google.protobuf.Any" is not defined.
protoc-gen-swagger/options/annotations.proto:7:1: Import "protoc-gen-swagger/options/openapiv2.proto" was not found or had errors.
protoc-gen-swagger/options/annotations.proto:8:1: Import "google/protobuf/descriptor.proto" was not found or had errors.
protoc-gen-swagger/options/annotations.proto:10:8: "google.protobuf.FileOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:17:8: "google.protobuf.MethodOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:24:8: "google.protobuf.MessageOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:31:8: "google.protobuf.ServiceOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:38:8: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto:32:1: Import "google/protobuf/descriptor.proto" was not found or had errors.
github.com/gogo/protobuf/gogoproto/gogo.proto:38:8: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.

make generate produces an error on centos

when i exec make generate in my centos , it comes:

# Generate gogo, gRPC-Gateway, swagger, go-validators output.
#
# -I declares import folders, in order of importance
# This is how proto resolves the protofile imports.
# It will check for the protofile relative to each of these
# folders and use the first one it finds.
#
# --gogo_out generates GoGo Protobuf output with gRPC plugin enabled.
# --grpc-gateway_out generates gRPC-Gateway output.
# --swagger_out generates an OpenAPI 2.0 specification for our gRPC-Gateway endpoints.
# --govalidators_out generates Go validation files for our messages types, if specified.
#
# The lines starting with Mgoogle/... are proto import replacements,
# which cause the generated file to import the specified packages
# instead of the go_package's declared by the imported protof files.
#
# $GOPATH/src is the output directory. It is relative to the GOPATH/src directory
# since we've specified a go_package option relative to that directory.
#
# proto/example.proto is the location of the protofile we use.
protoc \
		-I proto \
		-I vendor/github.com/grpc-ecosystem/grpc-gateway/ \
		-I vendor/github.com/gogo/googleapis/ \
		-I vendor/ \
		--gogo_out=plugins=grpc,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
		--grpc-gateway_out=\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
		--swagger_out=third_party/OpenAPI/ \
		--govalidators_out=gogoimport=true,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src \
		proto/example.proto
google/protobuf/empty.proto: File not found.
google/protobuf/timestamp.proto: File not found.
google/protobuf/duration.proto: File not found.
google/protobuf/field_mask.proto: File not found.
google/protobuf/descriptor.proto: File not found.
google/api/annotations.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
google/api/annotations.proto:28:8: "google.protobuf.MethodOptions" is not defined.
google/protobuf/any.proto: File not found.
protoc-gen-swagger/options/openapiv2.proto: Import "google/protobuf/any.proto" was not found or had errors.
protoc-gen-swagger/options/openapiv2.proto:131:3: "google.protobuf.Any" is not defined.
protoc-gen-swagger/options/annotations.proto: Import "protoc-gen-swagger/options/openapiv2.proto" was not found or had errors.
protoc-gen-swagger/options/annotations.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
protoc-gen-swagger/options/annotations.proto:10:8: "google.protobuf.FileOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:17:8: "google.protobuf.MethodOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:24:8: "google.protobuf.MessageOptions" is not defined.
protoc-gen-swagger/options/annotations.proto:31:8: "google.protobuf.ServiceOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
github.com/gogo/protobuf/gogoproto/gogo.proto:38:8: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.EnumOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto:46:8: "google.protobuf.EnumValueOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto:50:8: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FileOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto:89:8: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.MessageOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto:123:8: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/gogo/protobuf/gogoproto/gogo.proto: "google.protobuf.FieldOptions" is not defined.
github.com/mwitkow/go-proto-validators/validator.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
github.com/mwitkow/go-proto-validators/validator.proto:18:8: "google.protobuf.FieldOptions" is not defined.
example.proto: Import "google/protobuf/empty.proto" was not found or had errors.
example.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
example.proto: Import "google/protobuf/duration.proto" was not found or had errors.
example.proto: Import "google/protobuf/field_mask.proto" was not found or had errors.
example.proto: Import "google/api/annotations.proto" was not found or had errors.
example.proto: Import "protoc-gen-swagger/options/annotations.proto" was not found or had errors.
example.proto: Import "github.com/gogo/protobuf/gogoproto/gogo.proto" was not found or had errors.
example.proto: Import "github.com/mwitkow/go-proto-validators/validator.proto" was not found or had errors.
example.proto:82:5: "google.protobuf.Timestamp" is not defined.
example.proto:97:5: "google.protobuf.FieldMask" is not defined.
example.proto:102:5: "google.protobuf.Timestamp" is not defined.
example.proto:106:5: "google.protobuf.Duration" is not defined.
example.proto:43:32: "google.protobuf.Empty" is not defined.
make: *** [generate] Error 1

and exec make install is ok

make install

go install \
		./vendor/github.com/gogo/protobuf/protoc-gen-gogo \
		./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
		./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
		./vendor/github.com/mwitkow/go-proto-validators/protoc-gen-govalidators \
		./vendor/github.com/rakyll/statik

and when i exec make generate on my two mac, one is ok, but anther is failed.

Code generation a royal pain

I am trying to generate code from a .proto file that is basic but good enough to get me started. I have tried for several ours following grpc-example, to no avail. I know I am missing something for sure and here is what I have done so far:

syntax="proto3";

package somepackage

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";

option go_package = "client";

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
  info: {
    version: "1.0";
  };
  external_docs: {
    url: "https://localhost:9090/bakalr/api";
    description: "Bakalr Payment Services";
  }
  schemes: HTTPS;
};

// Enable custom Marshal method.
option (gogoproto.marshaler_all) = true;
// Enable custom Unmarshal method.
option (gogoproto.unmarshaler_all) = true;
// Enable custom Size method (Required by Marshal and Unmarshal).
option (gogoproto.sizer_all) = true;
// Enable registration with golang/protobuf for the grpc-gateway.
option (gogoproto.goproto_registration) = true;
// Enable generation of XXX_MessageName methods for grpc-go/status.
option (gogoproto.messagename_all) = true;

service ClientService {
  rpc RegisterClient(Client) returns (Client){
    option (google.api.http) = {
      post: "/api/v1/clients"
      body: "*"
    };
  }
}

enum ClientType {
  unknown = 0;
  mobile = 1;
  web = 2;
  iot = 3;
  pinpad = 4;
  server = 5;
}

message Client {
  string id = 1[(gogoproto.customname) = "ID"];
  ClientType ClientType = 2[(validator.field) = {
    msg_exists : true
    human_error: "Client type must not be unknown"
  }];
  google.protobuf.Timestamp registeredOn = 3[
    (gogoproto.stdtime) = true
  ];
}

The thing is I cannot get this to generate, I get this error Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,: No such file or directory every time I try to generate the code out of that .proto file.

generate: install
	protoc \
		-I client \
		--gogoslick_out=plugins=grpc,\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src/ \
					--grpc-gateway_out=\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src/ \
					--swagger_out=third_party/OpenAPI/ \
					--govalidators_out=gogoimport=true,\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src \
					client/client.proto
install:
	go get \
		github.com/gogo/protobuf/protoc-gen-gogo \
		github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
		github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
		github.com/mwitkow/go-proto-validators/protoc-gen-govalidators \
		github.com/rakyll/statik

I can verify that:

google/protobuf/timestamp.proto
google/api/annotations.proto
google/protobuf/field_mask.proto

Are present in:

github.com/gogo/protobuf/types
github.com/gogo/googleapis/google/api

respectively.

Please let me know what I am missing here.

go version go1.11.2 darwin/amd64
go modules 

FieldMask demo is wrong

In your example, try updating a user's role for example. It doesn't update it.

This is because you've set allow_patch_update=false which means grpc-gateway will not automatically fill the field mask for you, but you also put user instead of * in your service definition which means that swagger won't include the field mask so the user can't set it.
In other words, the update endpoint can't do anything currently.

Changing to * will allow the user to set the field mask which will work but not user friendly.

We were looking for a way to make gogo-proto and allow_patch_update=true to work successfully together (which is how I found your example in the first place), but we didn't find anything on that topic (the field mask type is different from go-protobuf). Any idea?

Add client example

@yurishkuro showed that users of this repository could benefit of a good example of a client using the server. I would like the following to be shown with this client:

  1. It should connect to the server over TLS (using the self signed cert)
  2. It should attempt to create a user that is not an admin, and parse the error returned.
  3. It should then create a user that is an admin.
  4. Finally it should list all users, showing how to iterate over a server side stream.

make generate produces an error on MacOS

 ~/go/src/github.com/davidklassen/grpc-example/ master make generate
# Generate gogo, gRPC-Gateway, swagger, go-validators output.
#
# -I declares import folders, in order of importance
# This is how proto resolves the protofile imports.
# It will check for the protofile relative to each of these
# folders and use the first one it finds.
#
# --gogo_out generates GoGo Protobuf output with gRPC plugin enabled.
# --grpc-gateway_out generates gRPC-Gateway output.
# --swagger_out generates an OpenAPI 2.0 specification for our gRPC-Gateway endpoints.
# --govalidators_out generates Go validation files for our messages types, if specified.
#
# The lines starting with Mgoogle/... are proto import replacements,
# which cause the generated file to import the specified packages
# instead of the go_package's declared by the imported protof files.
#
# $GOPATH/src is the output directory. It is relative to the GOPATH/src directory
# since we've specified a go_package option relative to that directory.
#
# proto/example.proto is the location of the protofile we use.
protoc \
		-I proto \
		-I vendor/github.com/grpc-ecosystem/grpc-gateway/ \
		-I vendor/github.com/gogo/googleapis/ \
		-I vendor/ \
		--gogo_out=plugins=grpc,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
		--grpc-gateway_out=\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src/ \
		--swagger_out=third_party/OpenAPI/ \
		--govalidators_out=gogoimport=true,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
$GOPATH/src \
		proto/example.proto
# Workaround for https://github.com/grpc-ecosystem/grpc-gateway/issues/229.
sed -i "s/empty.Empty/types.Empty/g" proto/example.pb.gw.go
sed: 1: "proto/example.pb.gw.go": extra characters at the end of p command
make: *** [generate] Error 1

Investigate problem with use of part of message

At work I ran into a problem with the following definition:

service Bla {
    rpc GetBla(GetBlaRequest) returns (Bla) {
        option (google.api.http) = {
            post: "/api/v1/{bla_id}"
            body: "bla"
        };
}

message Bla {
    string something = 1;
}

message GetBlaRequest {
    string bla_id = 1;
    Bla bla = 2;
}

It resulted in an error like:

unexpected type **bla.Bla does not implement proto.Message

The error originates from this line in the generated grpc-gateway code:

if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Bla); err != nil {

I have seen errors like this before in the github.com/gogo/gateway JSONPb marshaller, but thought they were fixed. Investigate whether this is a problem still.

how to replace google's protos when used in grpc gateway request

For example

// The file manager service definition.
service FileManager {
    rpc Hello(google.protobuf.Empty) returns (google.protobuf.Empty) {
        option (google.api.http) = {
            get: "/v1/hello"
        };
        option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
            responses: {
                key: "200"
            }
        };
    }
}

the code will be generate just like below

func request_FileManager_Hello_0(ctx context.Context, marshaler runtime.Marshaler, client FileManagerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq empty.Empty
	var metadata runtime.ServerMetadata

	msg, err := client.Hello(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

empty.Empty can not be found by go when it be replaced by github.com/gogo/protobuf/types.
How can i fix it?

Is it possible to remove pointer on params and response in gRPC ?

Hello gogo, thanks for your amazing library.

I use a lot [(gogoproto.nullable) = true]; and i recently switched to gRPC but i can't find a way to remove pointers on generated interface methods.
e.g:

  // .proto:
    rpc Subscribe(dto.Subscribe) returns (google.protobuf.Empty);

  // .pb.go:
	Subscribe(ctx context.Context, in *dto.Subscribe, opts ...grpc.CallOption) (*types.Empty, error)

Instead i'd like to have

  // .pb.go:
	Subscribe(ctx context.Context, in dto.Subscribe, opts ...grpc.CallOption) (types.Empty, error)

Is there any way to do this with current extensions ?

Thanks

Create a unit test and a travis job

Not only will this help to maintain the example, but it will also be nice an example of how to setup a travis job with gogoprotobuf and grpc.

Open source license missing?

Hello!

Could you please consider putting this repo under an open source license?
I am asking because I working in an environment that has a regulation in place that forbids using this example as a starting point when it is not under an open source license.
Preferable would be a permissive open source license like MIT or Apache 2.0
But that is up to you.

Many regards,

Michael

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.