peridot/vendor/github.com/gogo/status
Mustafa Gezen ad0f7a5305
Major upgrades
Upgrade to Go 1.20.5, Hydra v2 SDK, rules-go v0.44.2 (with proper resolves), protobuf v25.3 and mass upgrade of Go dependencies.
2024-03-17 08:06:08 +01:00
..
.gitignore Initial commit 2022-07-07 22:13:21 +02:00
BUILD.bazel Major upgrades 2024-03-17 08:06:08 +01:00
LICENSE Initial commit 2022-07-07 22:13:21 +02:00
README.md Initial commit 2022-07-07 22:13:21 +02:00
status.go Initial commit 2022-07-07 22:13:21 +02:00

Status

This is a convenience package for users of gogo/protobuf to be able to use their gogo/protobuf generated message easily and transparently with the gRPC status error structure.

It requires Go gRPC version 1.11 or above to successfully transmit statuses over the gRPC transport.

Use

Use as you would the normal grpc/status package:

return status.Error(codes.NotFound, "no such user")
st := status.New(codes.FailedPrecondition, "wrong user role")
detSt, err := st.WithDetails(&rpc.BadRequest{
    FieldViolations: []*rpc.BadRequest_FieldViolation{
        {
            Field:       "role",
            Description: "The first user created must have the role of an ADMIN",
        },
    },
})
if err == nil {
    return detSt.Err()
}
return st.Err()

License

The code is 95% copied from the official gRPC status package, so the gRPC License applies.

Changes

The changes applied include changing the use of the golang/protobuf packages to gogo/protobuf, and changing the generated files from google.golang.org/genproto/googleapis to github.com/gogo/googleapis/.

We've also created an implicit interface fulfilled by all gogo/status errors, for use with grpc/status and the gRPC runtime libraries.