example

package
v0.0.0-...-cdc2994 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package example is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var (
	ErrInvalidLength        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflow          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group")
)
View Source
var File_errors_example_proto_example_proto protoreflect.FileDescriptor
View Source
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

func RegisterHelloHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

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 (m *Error) CloneMessageVT() proto.Message

func (*Error) CloneVT

func (m *Error) CloneVT() *Error

func (*Error) Descriptor deprecated

func (*Error) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) EqualMessageVT

func (this *Error) EqualMessageVT(thatMsg proto.Message) bool

func (*Error) EqualVT

func (this *Error) EqualVT(that *Error) bool

func (*Error) GetCategory

func (x *Error) GetCategory() ErrorCategory

func (*Error) GetId

func (x *Error) GetId() string

func (*Error) GetMsg

func (x *Error) GetMsg() string

func (*Error) GetRequest

func (x *Error) GetRequest() *anypb.Any

func (*Error) GetType

func (x *Error) GetType() ErrorType

func (*Error) MarshalToSizedBufferVT

func (m *Error) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Error) MarshalToSizedBufferVTStrict

func (m *Error) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)

func (*Error) MarshalToVT

func (m *Error) MarshalToVT(dAtA []byte) (int, error)

func (*Error) MarshalToVTStrict

func (m *Error) MarshalToVTStrict(dAtA []byte) (int, error)

func (*Error) MarshalVT

func (m *Error) MarshalVT() (dAtA []byte, err error)

func (*Error) MarshalVTStrict

func (m *Error) MarshalVTStrict() (dAtA []byte, err error)

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset

func (x *Error) Reset()

func (*Error) SizeVT

func (m *Error) SizeVT() (n int)

func (*Error) String

func (x *Error) String() string

func (*Error) UnmarshalVT

func (m *Error) UnmarshalVT(dAtA []byte) error

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) Enum

func (x ErrorCategory) Enum() *ErrorCategory

func (ErrorCategory) EnumDescriptor deprecated

func (ErrorCategory) EnumDescriptor() ([]byte, []int)

Deprecated: Use ErrorCategory.Descriptor instead.

func (ErrorCategory) Number

func (ErrorCategory) String

func (x ErrorCategory) String() string

func (ErrorCategory) Type

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) Enum

func (x ErrorType) Enum() *ErrorType

func (ErrorType) EnumDescriptor deprecated

func (ErrorType) EnumDescriptor() ([]byte, []int)

Deprecated: Use ErrorType.Descriptor instead.

func (ErrorType) Number

func (x ErrorType) Number() protoreflect.EnumNumber

func (ErrorType) String

func (x ErrorType) String() string

func (ErrorType) Type

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 (m *HelloReq) CloneMessageVT() proto.Message

func (*HelloReq) CloneVT

func (m *HelloReq) CloneVT() *HelloReq

func (*HelloReq) Descriptor deprecated

func (*HelloReq) Descriptor() ([]byte, []int)

Deprecated: Use HelloReq.ProtoReflect.Descriptor instead.

func (*HelloReq) EqualMessageVT

func (this *HelloReq) EqualMessageVT(thatMsg proto.Message) bool

func (*HelloReq) EqualVT

func (this *HelloReq) EqualVT(that *HelloReq) bool

func (*HelloReq) GetName

func (x *HelloReq) GetName() string

func (*HelloReq) MarshalToSizedBufferVT

func (m *HelloReq) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*HelloReq) MarshalToSizedBufferVTStrict

func (m *HelloReq) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)

func (*HelloReq) MarshalToVT

func (m *HelloReq) MarshalToVT(dAtA []byte) (int, error)

func (*HelloReq) MarshalToVTStrict

func (m *HelloReq) MarshalToVTStrict(dAtA []byte) (int, error)

func (*HelloReq) MarshalVT

func (m *HelloReq) MarshalVT() (dAtA []byte, err error)

func (*HelloReq) MarshalVTStrict

func (m *HelloReq) MarshalVTStrict() (dAtA []byte, err error)

func (*HelloReq) ProtoMessage

func (*HelloReq) ProtoMessage()

func (*HelloReq) ProtoReflect

func (x *HelloReq) ProtoReflect() protoreflect.Message

func (*HelloReq) Reset

func (x *HelloReq) Reset()

func (*HelloReq) SizeVT

func (m *HelloReq) SizeVT() (n int)

func (*HelloReq) String

func (x *HelloReq) String() string

func (*HelloReq) UnmarshalVT

func (m *HelloReq) UnmarshalVT(dAtA []byte) error

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 (m *HelloResp) CloneMessageVT() proto.Message

func (*HelloResp) CloneVT

func (m *HelloResp) CloneVT() *HelloResp

func (*HelloResp) Descriptor deprecated

func (*HelloResp) Descriptor() ([]byte, []int)

Deprecated: Use HelloResp.ProtoReflect.Descriptor instead.

func (*HelloResp) EqualMessageVT

func (this *HelloResp) EqualMessageVT(thatMsg proto.Message) bool

func (*HelloResp) EqualVT

func (this *HelloResp) EqualVT(that *HelloResp) bool

func (*HelloResp) GetMsg

func (x *HelloResp) GetMsg() string

func (*HelloResp) MarshalToSizedBufferVT

func (m *HelloResp) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*HelloResp) MarshalToSizedBufferVTStrict

func (m *HelloResp) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error)

func (*HelloResp) MarshalToVT

func (m *HelloResp) MarshalToVT(dAtA []byte) (int, error)

func (*HelloResp) MarshalToVTStrict

func (m *HelloResp) MarshalToVTStrict(dAtA []byte) (int, error)

func (*HelloResp) MarshalVT

func (m *HelloResp) MarshalVT() (dAtA []byte, err error)

func (*HelloResp) MarshalVTStrict

func (m *HelloResp) MarshalVTStrict() (dAtA []byte, err error)

func (*HelloResp) ProtoMessage

func (*HelloResp) ProtoMessage()

func (*HelloResp) ProtoReflect

func (x *HelloResp) ProtoReflect() protoreflect.Message

func (*HelloResp) Reset

func (x *HelloResp) Reset()

func (*HelloResp) SizeVT

func (m *HelloResp) SizeVT() (n int)

func (*HelloResp) String

func (x *HelloResp) String() string

func (*HelloResp) UnmarshalVT

func (m *HelloResp) UnmarshalVT(dAtA []byte) error

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.

func (UnimplementedHelloServer) Hello

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.

Jump to

Keyboard shortcuts

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