gRPC to JSON proxy generator following the gRPC HTTP spec

Overview

gRPC-Gateway

gRPC to JSON proxy generator following the gRPC HTTP spec

About

The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.

This helps you provide your APIs in both gRPC and RESTful style at the same time.

Docs

You can read our docs at:

Testimonials

We use the gRPC-Gateway to serve millions of API requests per day, and have been since 2018 and through all of that, we have never had any issues with it.

- William Mill, Ad Hoc

Background

gRPC is great -- it generates API clients and server stubs in many programming languages, it is fast, easy-to-use, bandwidth-efficient and its design is combat-proven by Google. However, you might still want to provide a traditional RESTful JSON API as well. Reasons can range from maintaining backward-compatibility, supporting languages or clients that are not well supported by gRPC, to simply maintaining the aesthetics and tooling involved with a RESTful JSON architecture.

This project aims to provide that HTTP+JSON interface to your gRPC service. A small amount of configuration in your service to attach HTTP semantics is all that's needed to generate a reverse-proxy with this library.

Installation

The gRPC-Gateway requires a local installation of the Google protocol buffers compiler protoc v3.0.0 or above. Please install this via your local package manager or by downloading one of the releases from the official repository:

https://github.com/protocolbuffers/protobuf/releases

The following instructions assume you are using Go Modules for dependency management. Use a tool dependency to track the versions of the following executable packages:

// +build tools

package tools

import (
    _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
    _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
    _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
    _ "google.golang.org/protobuf/cmd/protoc-gen-go"
)

Run go mod tidy to resolve the versions. Install by running

$ go install \
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
    google.golang.org/protobuf/cmd/protoc-gen-go \
    google.golang.org/grpc/cmd/protoc-gen-go-grpc

This will place four binaries in your $GOBIN;

  • protoc-gen-grpc-gateway
  • protoc-gen-openapiv2
  • protoc-gen-go
  • protoc-gen-go-grpc

Make sure that your $GOBIN is in your $PATH.

Usage

  1. Define your gRPC service using protocol buffers

    your_service.proto:

     syntax = "proto3";
     package your.service.v1;
     option go_package = "github.com/yourorg/yourprotos/gen/go/your/service/v1";
     message StringMessage {
       string value = 1;
     }
    
     service YourService {
       rpc Echo(StringMessage) returns (StringMessage) {}
     }
  2. Generate gRPC stubs

    This step generates the gRPC stubs that you can use to implement the service and consume from clients:

    Here's an example of what a protoc command might look like to generate Go stubs:

    protoc -I . \
       --go_out ./gen/go/ --go_opt paths=source_relative \
       --go-grpc_out ./gen/go/ --go-grpc_opt paths=source_relative \
       your/service/v1/your_service.proto
  3. Implement your service in gRPC as usual

    1. (Optional) Generate gRPC stub in the other programming languages.

    For example, the following generates gRPC code for Ruby based on your/service/v1/your_service.proto:

    protoc -I . --ruby_out ./gen/ruby your/service/v1/your_service.proto
    
    protoc -I . --grpc-ruby_out ./gen/ruby your/service/v1/your_service.proto
    1. Add the googleapis-common-protos gem (or your language equivalent) as a dependency to your project.
    2. Implement your gRPC service stubs
  4. Generate reverse-proxy using protoc-gen-grpc-gateway

    At this point, you have 3 options:

    • no further modifications, use the default mapping to HTTP semantics (method, path, etc.)
      • this will work on any .proto file, but will not allow setting HTTP paths, request parameters or similar
    • additional .proto modifications to use a custom mapping
      • relies on parameters in the .proto file to set custom HTTP mappings
    • no .proto modifications, but use an external configuration file
      • relies on an external configuration file to set custom HTTP mappings
      • mostly useful when the source proto file isn't under your control
    1. Using the default mapping

    This requires no additional modification to the .proto file but does require enabling a specific option when executing the plugin. The generate_unbound_methods should be enabled.

    Here's what a protoc execution might look like with this option enabled:

       protoc -I . --grpc-gateway_out ./gen/go \
         --grpc-gateway_opt logtostderr=true \
         --grpc-gateway_opt paths=source_relative \
         --grpc-gateway_opt generate_unbound_methods=true \
         your/service/v1/your_service.proto
    1. With custom annotations

    Add a google.api.http annotation to your .proto file

    your_service.proto:

     syntax = "proto3";
     package your.service.v1;
     option go_package = "github.com/yourorg/yourprotos/gen/go/your/service/v1";
    +
    +import "google/api/annotations.proto";
    +
     message StringMessage {
       string value = 1;
     }
    
     service YourService {
    -  rpc Echo(StringMessage) returns (StringMessage) {}
    +  rpc Echo(StringMessage) returns (StringMessage) {
    +    option (google.api.http) = {
    +      post: "/v1/example/echo"
    +      body: "*"
    +    };
    +  }
     }

    You will need to provide the required third party protobuf files to the protoc compiler. They are included in this repo under the third_party/googleapis folder, and we recommend copying them into your protoc generation file structure. If you've structured your proto files according to something like the Buf style guide, you could copy the files into a top-level ./google folder.

    See a_bit_of_everything.proto for examples of more annotations you can add to customize gateway behavior and generated OpenAPI output.

    Here's what a protoc execution might look like:

       protoc -I . --grpc-gateway_out ./gen/go \
         --grpc-gateway_opt logtostderr=true \
         --grpc-gateway_opt paths=source_relative \
         your/service/v1/your_service.proto
    1. External configuration If you do not want to (or cannot) modify the proto file for use with gRPC-Gateway you can alternatively use an external gRPC Service Configuration file. Check our documentation for more information.

    Here's what a protoc execution might look like with this option enabled:

       protoc -I . --grpc-gateway_out ./gen/go \
         --grpc-gateway_opt logtostderr=true \
         --grpc-gateway_opt paths=source_relative \
         --grpc-gateway_opt grpc_api_configuration=path/to/config.yaml \
         your/service/v1/your_service.proto
  5. Write an entrypoint for the HTTP reverse-proxy server

    package main
    
    import (
      "context"
      "flag"
      "net/http"
    
      "github.com/golang/glog"
      "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
      "google.golang.org/grpc"
    
      gw "github.com/yourorg/yourrepo/proto/gen/go/your/service/v1/your_service"  // Update
    )
    
    var (
      // command-line options:
      // gRPC server endpoint
      grpcServerEndpoint = flag.String("grpc-server-endpoint",  "localhost:9090", "gRPC server endpoint")
    )
    
    func run() error {
      ctx := context.Background()
      ctx, cancel := context.WithCancel(ctx)
      defer cancel()
    
      // Register gRPC server endpoint
      // Note: Make sure the gRPC server is running properly and accessible
      mux := runtime.NewServeMux()
      opts := []grpc.DialOption{grpc.WithInsecure()}
      err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux,  *grpcServerEndpoint, opts)
      if err != nil {
        return err
      }
    
      // Start HTTP server (and proxy calls to gRPC server endpoint)
      return http.ListenAndServe(":8081", mux)
    }
    
    func main() {
      flag.Parse()
      defer glog.Flush()
    
      if err := run(); err != nil {
        glog.Fatal(err)
      }
    }
  6. (Optional) Generate OpenAPI definitions using protoc-gen-openapiv2

    protoc -I . --openapiv2_out ./gen/openapiv2 --openapiv2_opt logtostderr=true your/service/v1/your_service.proto

    Note that this plugin also supports generating OpenAPI definitions for unannotated methods; use the generate_unbound_methods option to enable this.

Video intro

This GopherCon UK 2019 presentation from our maintainer @JohanBrandhorst provides a good intro to using the gRPC-Gateway. It uses the following boilerplate repo as a base: https://github.com/johanbrandhorst/grpc-gateway-boilerplate.

Parameters and flags

During code generation with protoc, flags to gRPC-Gateway tools must be passed through protoc using one of 2 patterns:

  • as part of the --_out protoc parameter: --_out=:
--grpc-gateway_out=logtostderr=true,repeated_path_param_separator=ssv:.
--openapiv2_out=logtostderr=true,repeated_path_param_separator=ssv:.
  • using additional --_opt parameters: --_opt=[,]*
--grpc-gateway_opt logtostderr=true,repeated_path_param_separator=ssv
# or separately
--grpc-gateway_opt logtostderr=true --grpc-gateway_opt repeated_path_param_separator=ssv

--openapiv2_opt logtostderr=true,repeated_path_param_separator=ssv
# or separately
--openapiv2_opt logtostderr=true --openapiv2_opt repeated_path_param_separator=ssv

protoc-gen-grpc-gateway supports custom mapping from Protobuf import to Golang import paths. They are compatible with the parameters with the same names in protoc-gen-go.

In addition, we also support the request_context parameter in order to use the http.Request's Context (only for Go 1.7 and above). This parameter can be useful to pass the request-scoped context between the gateway and the gRPC service.

protoc-gen-grpc-gateway also supports some more command line flags to control logging. You can give these flags together with the parameters above. Run protoc-gen-grpc-gateway --help for more details about the flags.

Similarly, protoc-gen-openapiv2 supports command-line flags to control OpenAPI output (for example, json_names_for_fields to output JSON names for fields instead of protobuf names). Run protoc-gen-openapiv2 --help for more flag details. Further OpenAPI customization is possible by annotating your .proto files with options from openapiv2.proto - see a_bit_of_everything.proto for examples.

More examples

More examples are available under the examples directory.

  • proto/examplepb/echo_service.proto, proto/examplepb/a_bit_of_everything.proto, proto/examplepb/unannotated_echo_service.proto: service definition
    • proto/examplepb/echo_service.pb.go, proto/examplepb/a_bit_of_everything.pb.go, proto/examplepb/unannotated_echo_service.pb.go: [generated] stub of the service
    • proto/examplepb/echo_service.pb.gw.go, proto/examplepb/a_bit_of_everything.pb.gw.go, proto/examplepb/uannotated_echo_service.pb.gw.go: [generated] reverse proxy for the service
    • proto/examplepb/unannotated_echo_service.yaml: gRPC API Configuration for unannotated_echo_service.proto
  • server/main.go: service implementation
  • main.go: entrypoint of the generated reverse proxy

To use the same port for custom HTTP handlers (e.g. serving swagger.json), gRPC-Gateway, and a gRPC server, see this example by CoreOS (and its accompanying blog post).

Features

Supported

  • Generating JSON API handlers.
  • Method parameters in the request body.
  • Method parameters in the request path.
  • Method parameters in the query string.
  • Enum fields in the path parameter (including repeated enum fields).
  • Mapping streaming APIs to newline-delimited JSON streams.
  • Mapping HTTP headers with Grpc-Metadata- prefix to gRPC metadata (prefixed with grpcgateway-)
  • Optionally emitting API definitions for OpenAPI (Swagger) v2.
  • Setting gRPC timeouts through inbound HTTP Grpc-Timeout header.
  • Partial support for gRPC API Configuration files as an alternative to annotation.
  • Automatically translating PATCH requests into Field Mask gRPC requests. See the docs for more information.

No plan to support

But patches are welcome.

  • Method parameters in HTTP headers.
  • Handling trailer metadata.
  • Encoding request/response body in XML.
  • True bi-directional streaming.

Mapping gRPC to HTTP

  • How gRPC error codes map to HTTP status codes in the response.
  • HTTP request source IP is added as X-Forwarded-For gRPC request header.
  • HTTP request host is added as X-Forwarded-Host gRPC request header.
  • HTTP Authorization header is added as authorization gRPC request header.
  • Remaining Permanent HTTP header keys (as specified by the IANA here are prefixed with grpcgateway- and added with their values to gRPC request header.
  • HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata (prefixed with grpcgateway-).
  • While configurable, the default {un,}marshaling uses protojson.

Contribution

See CONTRIBUTING.md.

License

gRPC-Gateway is licensed under the BSD 3-Clause License. See LICENSE.txt for more details.

Issues
  • Merge v2 into master

    Merge v2 into master

    Draft change of merging v2 into master. Probably have to freeze v2 and master from now until I can merge this. I'm going to come back to this and update things that are missing/incorrect before we can make the release.

    Fixes #1223

    cla: yes 
    opened by johanbrandhorst 40
  • Support HttpRule with field response

    Support HttpRule with field response

    This PR adds support optional response_body field for google.api.HttpRule. Also see PR: https://github.com/google/go-genproto/pull/87 and https://github.com/googleapis/googleapis/pull/512

    This version of code can work with current HttpRule implementation and with forked implementation with new field. This implementation does not break existing code.

    Also allow_repeated_fields_in_body flag added to make it possible using repeated fields in body and response_body. This flag can be used for slices in request and response.

    Also flag json_name_in_swgdef added to make it possible to use Field.GetJsonName() instead of Field.GetName() for generating swagger definitions. See: https://github.com/grpc-ecosystem/grpc-gateway/pull/681 for more info.

    cla: yes 
    opened by doroginin 39
  • v2 release planning

    v2 release planning

    I figured we should have an issue to track the outstanding work for tagging a first stable v2 version of the gateway and switching the default branches. I've looked through the issue tracker and I think these are some of the issues we want to tackle:

    • [x] Issues mentioned in https://github.com/grpc-ecosystem/grpc-gateway/pull/546, including:
      • [x] Emitting defaults (https://github.com/grpc-ecosystem/grpc-gateway/issues/233)
      • [x] Using jsonpb marshaller by default
      • [x] Changing the output of errors to match the JSON representation of a gRPC status (https://github.com/grpc-ecosystem/grpc-gateway/issues/1098).
      • [x] Adopt correct behaviour for custom verbs (see https://github.com/grpc-ecosystem/grpc-gateway/issues/224#issuecomment-426091809).
      • [x] Change default JSON marshalling to use camelCase (https://github.com/grpc-ecosystem/grpc-gateway/pull/540) (and update swagger: https://github.com/grpc-ecosystem/grpc-gateway/issues/375)
    • [x] Switch to using the new Go protobuf stack (depends on https://github.com/grpc/grpc-go/pull/3453) (https://github.com/grpc-ecosystem/grpc-gateway/pull/1165 is the first part of this). #1147 #1719
    • [x] Use rules_go version which support APIv2 well known types (https://github.com/bazelbuild/rules_go/issues/2514)
    • [x] Minimize public API per https://github.com/grpc-ecosystem/grpc-gateway/pull/1146
    • [x] Rename swagger to openapi (https://github.com/grpc-ecosystem/grpc-gateway/issues/675)
    • [x] Consolidate error handler configuration.
    • [x] Make HTTPBodyMarshaler behaviour the default
    • [x] Remove runtime.DisallowUnknownFields

    I will update this issue as we find more things we want to have in a v2 release. I've also updated the v2 milestone: https://github.com/grpc-ecosystem/grpc-gateway/milestone/3.

    opened by johanbrandhorst 36
  • add patch behavior

    add patch behavior

    this addresses #379

    If a binding is mapped to patch and the request message has exactly one FieldMask message in it, additional code is rendered for the gateway handler that will populate the FieldMask based on the request body.

    This handles two scenarios: The FieldMask is hidden from the REST request (as in the UpdateV2 example). In this case, the FieldMask is updated from the request body and set in the gRPC request message.

    The FieldMask is exposed to the REST request (as in the PatchWithFieldMaskInBody example). For this case, a check is made as to whether the FieldMask is nil/empty prior to populating with the request body. If it's not nil, then it converts the FieldMask paths from the REST (snake_case) to gRPC (PascalCase) format. Otherwise, it acts like the previous case.

    Additional comments of interest are inline on this PR.

    enhancement waiting on reporter cla: no 
    opened by dmacthedestroyer 35
  • 404s using colons in the middle of the last path segment

    404s using colons in the middle of the last path segment

    I have the following endpoint and user_ids of the format "user:"

      rpc GetUser(GetUserRequest) returns (GetUserResponse) {
        option (google.api.http) = {
          get: "/v0/users/{user_id}"
        };
      };
    

    I'm getting 404 status code and it doesn't hit my GetUser handler when I call this endpoint with user_ids of the format above. However, if I call the endpoint with a user_id that doesn't have a colon it (e.g. "user123") it does hit my GetUser handler. Url encoding the colon doesn't work either.

    What's even more interesting is if I add another colon to the end of the path, grpc-gateway parses the user_id into the correct format that I want. ("/v0/users/user:123:" -> user_id = "user:123"). Given this data point, I believe grpc-gateway is treating colons differently in the last path segment.

    For example here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-grpc-gateway/httprule/parse.go#L86 it strips off the last colon in the segment. Though this looks like the rule for parsing the endpoint path definition and not what is being used to parse incoming requests.

    bug help wanted 
    opened by charleschenster 35
  • Add a register, so that the gRPC service can be invoked in-process to provide a HTTP server.

    Add a register, so that the gRPC service can be invoked in-process to provide a HTTP server.

    sometimes we don't need the HTTP gateway to be a RPC. just convert the gRPC service to an HTTP service. this reduces one remote call.

    example code

    func main() {
    	s := grpc.NewServer(
    	)
    	srv := service{}
    	pb.RegisterExampleServiceServer(s, &srv)
    
    	ctx := context.Background()
    	ctx, cancel := context.WithCancel(ctx)
    	defer cancel()
    
    	mux := runtime.NewServeMux()
    	err := pb.RegisterExampleServiceHandlerServer(ctx, mux, &srv)
    	if err != nil {
    		log.Panic(err)
    	}
    
    	if err := http.ListenAndServe(serveAddr, mux); err != nil {
    		log.Fatalf("http failed to serve: %v", err)
    	}
    }
    
    enhancement waiting on reporter cla: yes 
    opened by hb-chen 33
  • Properly omit wrappers and google.protobuf.empty from swagger definitions

    Properly omit wrappers and google.protobuf.empty from swagger definitions

    • swaggerSchemaObject.Properties is now optional (pointer), because google.protobuf.Empty requires us to set Properties{} instead of nil, because this equals in Swagger to an empty JSON object (which is exactly what Empty represents and how the gateway treats it). If it's not a pointer, we can't distinguish between "not set" (in most cases, we don't want Properties to be set, instead usually just .Ref is set), and "set to an empty value e.g. Properties{} with length 0). We don't want Properties{} to occur except for specific cases, e.g. for Empty.
    • Wrappers and Empty are not rendered as definitions, now also for RPC Method input/output. instead, all necessary schema information is provided "in-line" via schema.type and schema.properties.
    • Empty is now omitted as well if it's input/output of a RPC Method.
    cla: yes 
    opened by birdayz 33
  • Support go modules

    Support go modules

    Steps you follow to reproduce the error:

    1. Using go1.11 outside of go path
    2. Run go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

    Returns

    go: finding github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway latest
    
    # github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor
    
    ../../go/pkg/mod/github.com/grpc-ecosystem/[email protected]/protoc-gen-grpc-gateway/descriptor/services.go:146:49: opts.ResponseBody undefined (type *annotations.HttpRule has no field or method ResponseBody)
    -->
    

    What did you expect to happen instead: Successfully added to mod file

    It seems like it's able to find the latest version 1.5.0, but then isn't up to date? The error that's output seems to be what was fixed with #731

    enhancement help wanted good first issue 
    opened by kasuboski 31
  • use Go templates in protofile comments

    use Go templates in protofile comments

    Introduce GO Templates into proto comments to allow more advanced documentation such as from external (markdown) files and automatically generated content based on the proto definitions.

    For example: The comments in this proto file:

    syntax = "proto3";
    
    package LoginTest;
    
    import "google/api/annotations.proto";
    
    service LoginService {
    
    // Logout
    // 
    // {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
    // It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
    // 
    // ## {{.RequestType.Name}}
    // | Field ID    | Name      | Type                                                       | Description                  |
    // | ----------- | --------- | ---------------------------------------------------------  | ---------------------------- | {{range .RequestType.Fields}}
    // | {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}  
    //  
    // ## {{.ResponseType.Name}}
    // | Field ID    | Name      | Type                                                       | Description                  |
    // | ----------- | --------- | ---------------------------------------------------------- | ---------------------------- | {{range .ResponseType.Fields}}
    // | {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}  
    rpc Logout (LogoutRequest) returns (LogoutReply) {
      option (google.api.http) = {
        post: "/v1/example/ekko"
        body: "*"
        additional_bindings {
          post: "/test/test/test"
        }
        };
      }
    }
    
    message LogoutRequest {
      // This field only contains this title
      string timeoflogout = 1;
      // This is the title
      //
      // This is the "Description" of field test
      // you can use as many newlines as you want
      //
      //
      // it will still format the same in the table
      int32 test = 2;
      // Array title
      repeated string stringarray = 3;
    }
    
    message LogoutReply {
      // Message that displays whether the logout was succesful or not
      string message = 1;
    }
    

    would generate the following documentation in Swagger UI:

    image

    or when imported in Postman:

    image

    cla: yes 
    opened by Jeremytjuh 28
  • protoc-gen-swagger: should well known types be nullable

    protoc-gen-swagger: should well known types be nullable

    • OpenAPI 3.0 support nullable [link] field to define schema can be null value.
    • go-swagger support vendor extensions for x-nullable [link]

    Should protoc-gen-swagger convert well know types to nullable type?

    enhancement help wanted openapi 
    opened by zheng1 28
  • Generate Swagger with Unique Operation IDs

    Generate Swagger with Unique Operation IDs

    This PR prepends the service name to the method name to generate unique operation IDs. Prior to this change, the swagger generator would produce spec non-compliant swagger when multiple services had shared method names. This is quite problematic for generic CRUD services with method names like Create, Delete, etc.

    cla: yes 
    opened by dadgar 27
  • Investigate whether HTTPRule parser allows invalid templates

    Investigate whether HTTPRule parser allows invalid templates

    As part of #2825, @oyvindwe mentioned that the HTTPRule parser may allow templates that will cause the OpenAPIv2 generator to generate invalid paths. Specifically:

    Does the HttpRule parser also allow other path templates outside the specification? Specifically : before a variable? The reason I am asking is that the the joining of the path in the generator assumes that only the last part can start with :.

    We should investigate whether this is the case, and if so, probably patch the openapiv2 generator to remove this assumption, as introducing errors for these templates now is a backwards incompatible change.

    Related to #2824.

    bug help wanted question 
    opened by johanbrandhorst 0
  • chore(deps): update module go to 1.19

    chore(deps): update module go to 1.19

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | go (source) | golang | minor | 1.17 -> 1.19 |


    Release Notes

    golang/go

    v1.19.0

    v1.18.5

    v1.18.4

    v1.18.3

    v1.18.2

    v1.18.1

    v1.18.0


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled due to failing status checks.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • Fix identifiers generated from snake-cased enums not matching pb.go definitions

    Fix identifiers generated from snake-cased enums not matching pb.go definitions

    References to other Issues or PRs

    Fixes #2776

    Have you read the Contributing Guidelines?

    Yes.

    Brief description of what is fixed or changed

    First add snake-cased enums to a_bit_of_everything.proto to reproduce the issue, and to path_enum.proto to recreate the scenario when importing snake-cased enums from another package. To fix, apply the CamelCasing function into the enum identifiers that reference those generated in the corresponding .pb.go file. As the enums are looped-through inside the template, the camel casing function needs to be registered into the template and be called there. Given the template not only generates the enum identifiers but it matches it with the corresponding import package, the CamelCasing function must ensure to CamelCase the identifier name but leave the package name/path intact, that's why introduced the CamelIdentifier function wrapping the Camel function.

    Other comments

    opened by jbaxx 2
  • Replace openapiv2 path template parser with httprule parser

    Replace openapiv2 path template parser with httprule parser

    We have at least two parsers for the http.proto template language;

    • In the httprule package, which is used by protoc-gen-grpc-gateway to generate the handler paths
    • In the genopenapi package to generate the OpenAPI paths.

    We should unify these two places, and we should be using the one in httprule. I did a little bit of investigating and I think it should be possible without too much work, and then we'd have consistency between the two generators.

    enhancement help wanted 
    opened by johanbrandhorst 0
  • Please document how to handle

    Please document how to handle "If-Match" or return 412 on PRECONDITION_FAILED

    I'm trying to implement "If-Match" headers using gRPC-Gateway.

    My first attempt was to return PRECONDITION_FAILED from my gRPC service after doing the ETag checks. At some point this worked in gRPC-Gateway, but this issue changed the behavior to no longer do that: https://github.com/grpc-ecosystem/grpc-gateway/issues/972

    Looking in the existing documentation this seems to imply that this is the correct place to set up custom http status codes https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/customizing_your_gateway/#controlling-http-response-status-codes. Unfortunately this does not seem to be called in the situation where I've returned PRECONDITION_FAILED.

    The following issue implies that what I should actually do is override the default http error codes in this situation: https://github.com/grpc-ecosystem/grpc-gateway/issues/1064. Unfortunately when I try the solution proffered in that issue I receive the following errors:

    ../../gateway/gateway.go:76:20: cannot assign to runtime.HTTPError
    ../../gateway/gateway.go:83:3: undefined: runtime.DefaultHTTPError
    

    I would greatly appreciate a complete example that shows how to customize the http return code or that otherwise gives the best guidance on how to handle something like "If-Match."

    opened by gnu-lorien 2
Releases(v2.11.1)
Owner
gRPC Ecosystem
gRPC Ecosystem that complements gRPC
gRPC Ecosystem
Solution & Framework for JSON-RPC over HTTP

JROH Solution & Framework for JSON-RPC over HTTP Why not OpenAPI? OpenAPI addresses the definition of RESTful APIs, when it comes to JSON-RPCs, some i

Go Toolkit 11 Mar 13, 2022
Golang 微服务框架,支持 grpc/http,支持多种注册中心 etcd,consul,mdns 等

一个用于构建分布式系统的工具集或者轻框架,支持 grpc 和 http ,支持多种注册中心 consul ,etcd , mdns 等。

徐旭 25 Jun 23, 2022
Social previews generator as a microservice.

ogimgd Social previews generator as a microservice. Can be used to generate images for og:image meta-tag. It runs as an HTTP server with a single endp

Dmitry Nikitenko 10 Apr 9, 2022
OpenAPI Client and Server Code Generator

This package contains a set of utilities for generating Go boilerplate code for services based on OpenAPI 3.0 API definitions

Discord Gophers 45 Jul 28, 2022
Proof-of-concept SLSA provenance generator for GitHub Actions

SLSA GitHub Actions Demo A proof-of-concept SLSA provenance generator for GitHub Actions. Background SLSA is a framework intended to codify and promot

SLSA Framework 82 Aug 6, 2022
A db proxy for distributed transaction, read write splitting and sharding! Support any language! It can be deployed as a sidecar in a pod.

DBPack DBPack means a database cluster tool pack. It can be deployed as a sidecar in a pod, it shields complex basic logic, so that business developme

null 262 Aug 2, 2022
Golang client for Ethereum and Flashbots JSON-RPC API calls.

Flashbots RPC client Fork of ethrpc with additional Flashbots RPC methods: FlashbotsGetUserStats FlashbotsCallBundle FlashbotsSendBundle FlashbotsSimu

Chris Hager 79 Aug 3, 2022
A library to generate go models from given json files

generate A library to generate go models from given json files Requirements Go 1

null 2 May 18, 2022
Poc-krakend: Allows you to create, modify and delete enpoints in "configuration.json" without restart the application.

poc-krakend Description This POC is for test dynamic (Hot reload) routes in krakend. Allows you to create, modify and delete enpoints in "configuratio

Arturo Elias 4 Jan 26, 2022
Go gRPC RabbitMQ email microservice

Go, RabbitMQ and gRPC Clean Architecture microservice ?? ??‍?? Full list what has been used: GRPC - gRPC RabbitMQ - RabbitMQ sqlx - Extensions to data

Alexander 111 Aug 6, 2022
Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Google Cloud Platform 12.6k Aug 4, 2022
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

AstraNet Toolkit 68 Apr 19, 2022
drpc is a lightweight, drop-in replacement for gRPC

drpc is a lightweight, drop-in replacement for gRPC

Storj Labs 1.1k Jul 28, 2022
Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported

Go Microservice Starter A boilerplate for flexible Go microservice. Table of contents Features Installation Todo List Folder Structures Features: Mult

Ahmad Saugi 14 Jul 28, 2022
Go microservices with REST, and gRPC using BFF pattern.

Go microservices with REST, and gRPC using BFF pattern. This repository contains backend services. Everything is dockerized and ready to

Oguzhan 140 Jul 24, 2022
A gRPC API for Warhammer Age of Sigmar

Warhammer ?? A gRPC API for Warhammer Age of Sigmar Intro ℹ️ Skip to Quick Start What is this? An API for creating, reading, deleting, and updating a

Britton Hayes 1 Oct 26, 2021
一款依赖 etcd 作为注册中心的 Golang 轻量级 GRPC 框架

Golang 微服务 GRPC 标准框架(轻量级) 特性介绍 可使用 etcd 集群或单节点作为注册中心 客户端请求服务端自带负载均衡 服务端启动后自动向 etcd 注册,默认每 10s 进行一次心跳续租 自带优雅停止 panic recover 服务端无需指定启动端口,当然你也可以通过 WithP

兰陵美酒郁金香丶❀ 2 Nov 11, 2021
Testing ground for CRUD backend using Golang, gRPC, protobufs

blog-example-service Simple example CRUD backend using Golang, gRPC, and protobufs. Using with MongoDB as the database (default) You will need a Mongo

Jordan Weiner 0 Dec 16, 2021
Just a quick demo of how you can use automatically generated protobuffer and gRPC code from buf.build

buf.build demo The purpose of this repository is to demonstrate how to use the services offered by buf.build for hosting protobuffer definitions and a

Bjørn Borud 0 Jan 4, 2022