Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncrypthic/protoc-gen-go-errors
https://github.com/ncrypthic/protoc-gen-go-errors
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ncrypthic/protoc-gen-go-errors
- Owner: ncrypthic
- License: gpl-3.0
- Created: 2022-06-03T16:52:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-03T16:53:44.000Z (over 2 years ago)
- Last Synced: 2024-10-11T18:32:46.405Z (about 1 month ago)
- Language: Go
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
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 identifier2. an enumerated gRPC status [code](https://www.grpc.io/docs/guides/error/#error-status-codes)
This will be transalated into real gRPC status code which will be used over the wire.An simple example will be like below
```protobuf
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
```sh
$ go install github.com/ncrypthic/proto-gen-go-errors
```2. Generate error definition Golang file
```sh
protoc --go-errors_out=: -I -I
```## LICENSE
GNU General Public License v3.0 or later
See [COPYING](COPYING) to see the full text.