Documentation
¶
Overview ¶
Package example is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
Index ¶
- Variables
- func RegisterHelloHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
- func RegisterHelloHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HelloClient) error
- func RegisterHelloHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, ...) (err error)
- func RegisterHelloHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HelloServer) error
- func RegisterHelloServer(s grpc.ServiceRegistrar, srv HelloServer)
- type Error
- func (m *Error) CloneMessageVT() proto.Message
- func (m *Error) CloneVT() *Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (this *Error) EqualMessageVT(thatMsg proto.Message) bool
- func (this *Error) EqualVT(that *Error) bool
- func (x *Error) GetCategory() ErrorCategory
- func (x *Error) GetId() string
- func (x *Error) GetMsg() string
- func (x *Error) GetRequest() *anypb.Any
- func (x *Error) GetType() ErrorType
- func (m *Error) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *Error) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)
- func (m *Error) MarshalToVT(dAtA []byte) (int, error)
- func (m *Error) MarshalToVTStrict(dAtA []byte) (int, error)
- func (m *Error) MarshalVT() (dAtA []byte, err error)
- func (m *Error) MarshalVTStrict() (dAtA []byte, err error)
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (m *Error) SizeVT() (n int)
- func (x *Error) String() string
- func (m *Error) UnmarshalVT(dAtA []byte) error
- type ErrorCategory
- func (ErrorCategory) Descriptor() protoreflect.EnumDescriptor
- func (x ErrorCategory) Enum() *ErrorCategory
- func (ErrorCategory) EnumDescriptor() ([]byte, []int)deprecated
- func (x ErrorCategory) Number() protoreflect.EnumNumber
- func (x ErrorCategory) String() string
- func (ErrorCategory) Type() protoreflect.EnumType
- type ErrorType
- type HelloClient
- type HelloReq
- func (m *HelloReq) CloneMessageVT() proto.Message
- func (m *HelloReq) CloneVT() *HelloReq
- func (*HelloReq) Descriptor() ([]byte, []int)deprecated
- func (this *HelloReq) EqualMessageVT(thatMsg proto.Message) bool
- func (this *HelloReq) EqualVT(that *HelloReq) bool
- func (x *HelloReq) GetName() string
- func (m *HelloReq) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *HelloReq) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)
- func (m *HelloReq) MarshalToVT(dAtA []byte) (int, error)
- func (m *HelloReq) MarshalToVTStrict(dAtA []byte) (int, error)
- func (m *HelloReq) MarshalVT() (dAtA []byte, err error)
- func (m *HelloReq) MarshalVTStrict() (dAtA []byte, err error)
- func (*HelloReq) ProtoMessage()
- func (x *HelloReq) ProtoReflect() protoreflect.Message
- func (x *HelloReq) Reset()
- func (m *HelloReq) SizeVT() (n int)
- func (x *HelloReq) String() string
- func (m *HelloReq) UnmarshalVT(dAtA []byte) error
- type HelloResp
- func (m *HelloResp) CloneMessageVT() proto.Message
- func (m *HelloResp) CloneVT() *HelloResp
- func (*HelloResp) Descriptor() ([]byte, []int)deprecated
- func (this *HelloResp) EqualMessageVT(thatMsg proto.Message) bool
- func (this *HelloResp) EqualVT(that *HelloResp) bool
- func (x *HelloResp) GetMsg() string
- func (m *HelloResp) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *HelloResp) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)
- func (m *HelloResp) MarshalToVT(dAtA []byte) (int, error)
- func (m *HelloResp) MarshalToVTStrict(dAtA []byte) (int, error)
- func (m *HelloResp) MarshalVT() (dAtA []byte, err error)
- func (m *HelloResp) MarshalVTStrict() (dAtA []byte, err error)
- func (*HelloResp) ProtoMessage()
- func (x *HelloResp) ProtoReflect() protoreflect.Message
- func (x *HelloResp) Reset()
- func (m *HelloResp) SizeVT() (n int)
- func (x *HelloResp) String() string
- func (m *HelloResp) UnmarshalVT(dAtA []byte) error
- type HelloServer
- type UnimplementedHelloServer
- type UnsafeHelloServer
Constants ¶
This section is empty.
Variables ¶
var ( ErrorCategory_name = map[int32]string{ 0: "EC_UNKNOWN", 1: "EC_REQUEST", 2: "EC_SAFETY", 3: "EC_PERMISSION", 4: "EC_RESOURCE_EXHAUSTED", 5: "EC_INTERNAL", } ErrorCategory_value = map[string]int32{ "EC_UNKNOWN": 0, "EC_REQUEST": 1, "EC_SAFETY": 2, "EC_PERMISSION": 3, "EC_RESOURCE_EXHAUSTED": 4, "EC_INTERNAL": 5, } )
Enum value maps for ErrorCategory.
var ( ErrorType_name = map[int32]string{ 0: "ET_UNKNOWN", 1: "ET_BAD_REQUEST", 101: "ET_DEAD_TIMER", 102: "ET_CLUSTER_HEALTH", 201: "ET_PERMISSION_DENIED", } ErrorType_value = map[string]int32{ "ET_UNKNOWN": 0, "ET_BAD_REQUEST": 1, "ET_DEAD_TIMER": 101, "ET_CLUSTER_HEALTH": 102, "ET_PERMISSION_DENIED": 201, } )
Enum value maps for ErrorType.
var ( ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflow = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") )
var File_errors_example_proto_example_proto protoreflect.FileDescriptor
var Hello_ServiceDesc = grpc.ServiceDesc{ ServiceName: "github.com.gostdlib.base.proto.example.Hello", HandlerType: (*HelloServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Hello", Handler: _Hello_Hello_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "errors/example/proto/example.proto", }
Hello_ServiceDesc is the grpc.ServiceDesc for Hello service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
Functions ¶
func RegisterHelloHandler ¶
RegisterHelloHandler registers the http handlers for service Hello to "mux". The handlers forward requests to the grpc endpoint over "conn".
func RegisterHelloHandlerClient ¶
func RegisterHelloHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HelloClient) error
RegisterHelloHandlerClient registers the http handlers for service Hello to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "HelloClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "HelloClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "HelloClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterHelloHandlerFromEndpoint ¶
func RegisterHelloHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)
RegisterHelloHandlerFromEndpoint is same as RegisterHelloHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterHelloHandlerServer ¶
func RegisterHelloHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HelloServer) error
RegisterHelloHandlerServer registers the http handlers for service Hello to "mux". UnaryRPC :call HelloServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterHelloHandlerFromEndpoint instead. GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterHelloServer ¶
func RegisterHelloServer(s grpc.ServiceRegistrar, srv HelloServer)
Types ¶
type Error ¶
type Error struct { // The ID of the request. This is the UUIDv7 identity of the request. Id string `protobuf:"bytes,1,opt,name=Id,proto3" json:"Id,omitempty"` // The category of the error. Category ErrorCategory `` /* 128-byte string literal not displayed */ // The type of the error. Type ErrorType `protobuf:"varint,3,opt,name=Type,proto3,enum=github.com.gostdlib.base.proto.example.ErrorType" json:"Type,omitempty"` // The error message. This may be an error string, JSON encoded, or both. Msg string `protobuf:"bytes,4,opt,name=Msg,proto3" json:"Msg,omitempty"` // The original request. Request *anypb.Any `protobuf:"bytes,5,opt,name=Request,proto3" json:"Request,omitempty"` // contains filtered or unexported fields }
Error provides details on an error. When a request fails, this will be JSON encoded with jsonpb in the status message that is returned.
func (*Error) CloneMessageVT ¶
func (*Error) Descriptor
deprecated
func (*Error) GetCategory ¶
func (x *Error) GetCategory() ErrorCategory
func (*Error) GetRequest ¶
func (*Error) MarshalToSizedBufferVT ¶
func (*Error) MarshalToSizedBufferVTStrict ¶
func (*Error) MarshalVTStrict ¶
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message
func (*Error) UnmarshalVT ¶
type ErrorCategory ¶
type ErrorCategory int32
ErrorCategory defines the category of an error.
const ( // The error is unknown. This is always a bug from the service. ErrorCategory_EC_UNKNOWN ErrorCategory = 0 // The error is caused by the request being incorrect. ErrorCategory_EC_REQUEST ErrorCategory = 1 // The error is caused by a safety issue. ErrorCategory_EC_SAFETY ErrorCategory = 2 // The error is caused by a permission issue. ErrorCategory_EC_PERMISSION ErrorCategory = 3 // The error is caused by a resource being exhausted. ErrorCategory_EC_RESOURCE_EXHAUSTED ErrorCategory = 4 // The error is caused by an internal issue. ErrorCategory_EC_INTERNAL ErrorCategory = 5 )
func (ErrorCategory) Descriptor ¶
func (ErrorCategory) Descriptor() protoreflect.EnumDescriptor
func (ErrorCategory) Enum ¶
func (x ErrorCategory) Enum() *ErrorCategory
func (ErrorCategory) EnumDescriptor
deprecated
func (ErrorCategory) EnumDescriptor() ([]byte, []int)
Deprecated: Use ErrorCategory.Descriptor instead.
func (ErrorCategory) Number ¶
func (x ErrorCategory) Number() protoreflect.EnumNumber
func (ErrorCategory) String ¶
func (x ErrorCategory) String() string
func (ErrorCategory) Type ¶
func (ErrorCategory) Type() protoreflect.EnumType
type ErrorType ¶
type ErrorType int32
ErrorType represents the type of the error.
const ( // The error type is unknown. This is always a bug from the service. ErrorType_ET_UNKNOWN ErrorType = 0 // 1-100 are RPC errors. // // The error is caused by a bad request. ErrorType_ET_BAD_REQUEST ErrorType = 1 // 101-200 are safety errors. // // The error is caused by a dead timer. ErrorType_ET_DEAD_TIMER ErrorType = 101 // The error is caused by the cluster being unhealthy. ErrorType_ET_CLUSTER_HEALTH ErrorType = 102 // 201-300 are permission errors. // // The error is caused by permission being denied. ErrorType_ET_PERMISSION_DENIED ErrorType = 201 )
func (ErrorType) Descriptor ¶
func (ErrorType) Descriptor() protoreflect.EnumDescriptor
func (ErrorType) EnumDescriptor
deprecated
func (ErrorType) Number ¶
func (x ErrorType) Number() protoreflect.EnumNumber
func (ErrorType) Type ¶
func (ErrorType) Type() protoreflect.EnumType
type HelloClient ¶
type HelloClient interface { // A simple RPC. // // Obtains the feature at a given position. // // A feature with an empty name is returned if there's no feature at the given // position. Hello(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloResp, error) }
HelloClient is the client API for Hello service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewHelloClient ¶
func NewHelloClient(cc grpc.ClientConnInterface) HelloClient
type HelloReq ¶
type HelloReq struct { Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"` // contains filtered or unexported fields }
func (*HelloReq) CloneMessageVT ¶
func (*HelloReq) Descriptor
deprecated
func (*HelloReq) MarshalToSizedBufferVT ¶
func (*HelloReq) MarshalToSizedBufferVTStrict ¶
func (*HelloReq) MarshalVTStrict ¶
func (*HelloReq) ProtoMessage ¶
func (*HelloReq) ProtoMessage()
func (*HelloReq) ProtoReflect ¶
func (x *HelloReq) ProtoReflect() protoreflect.Message
func (*HelloReq) UnmarshalVT ¶
type HelloResp ¶
type HelloResp struct { Msg string `protobuf:"bytes,1,opt,name=Msg,proto3" json:"Msg,omitempty"` // contains filtered or unexported fields }
func (*HelloResp) CloneMessageVT ¶
func (*HelloResp) Descriptor
deprecated
func (*HelloResp) EqualMessageVT ¶
func (*HelloResp) MarshalToSizedBufferVT ¶
func (*HelloResp) MarshalToSizedBufferVTStrict ¶
func (*HelloResp) MarshalToVTStrict ¶
func (*HelloResp) MarshalVTStrict ¶
func (*HelloResp) ProtoMessage ¶
func (*HelloResp) ProtoMessage()
func (*HelloResp) ProtoReflect ¶
func (x *HelloResp) ProtoReflect() protoreflect.Message
func (*HelloResp) UnmarshalVT ¶
type HelloServer ¶
type HelloServer interface { // A simple RPC. // // Obtains the feature at a given position. // // A feature with an empty name is returned if there's no feature at the given // position. Hello(context.Context, *HelloReq) (*HelloResp, error) // contains filtered or unexported methods }
HelloServer is the server API for Hello service. All implementations must embed UnimplementedHelloServer for forward compatibility
type UnimplementedHelloServer ¶
type UnimplementedHelloServer struct { }
UnimplementedHelloServer must be embedded to have forward compatible implementations.
type UnsafeHelloServer ¶
type UnsafeHelloServer interface {
// contains filtered or unexported methods
}
UnsafeHelloServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to HelloServer will result in compilation errors.