protoc-gen-go-errors

command module
v0.0.0-...-5f94670 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

README

protoc-gen-go-errors

This protobuf plugins enables rpc method to list possible errors returned. The plugin will generate single, package level, Go error variable for every error listed. Server may use the generated error variable as return error and client Can catch the error with errors.Is() assertion.

Every error definition MUST contain two properties:

  1. arbitrary error code string This can be served as human friendly error identifier

  2. an enumerated gRPC status code This will be transalated into real gRPC status code which will be used over the wire.

An simple example will be like below

syntax="proto3";

import "protoc-gen-go-errors/proto/error.proto"

// ...

service Sample {
  rpc Method(Input) returns (Response) {
    option(errors.types) = {
       status: ALREADY_EXISTS,
       code: "err_email_exists"
    };
    option(errors.types) = {
       status: INVALID_ARGUMENT,
       code: "err_invalid_email"
    };
  }
}

Installation

  1. Install protoc-gen-go-errors
$ go install github.com/ncrypthic/proto-gen-go-errors
  1. Generate error definition Golang file
protoc --go-errors_out=:<dir> -I <path to protoc-gen-go-errors parent dir> -I <path to proto file directory> <proto_file_name>

LICENSE

GNU General Public License v3.0 or later

See COPYING to see the full text.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL