grpcutil

package
v0.0.0-...-ba97115 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 22 Imported by: 33

Documentation

Index

Constants

View Source
const MetadataMessageSize = "message-size"

MetadataMessageSize is grpc metadata key for message size.

Variables

View Source
var (
	ErrInvalidLengthErrorDetails = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowErrorDetails   = fmt.Errorf("proto: integer overflow")
)
View Source
var ErrorCause_name = map[int32]string{
	0: "UNKNOWN_CAUSE",
	1: "WRONG_CLUSTER_VALIDATION_LABEL",
}
View Source
var ErrorCause_value = map[string]int32{
	"UNKNOWN_CAUSE":                  0,
	"WRONG_CLUSTER_VALIDATION_LABEL": 1,
}

Functions

func AppendMessageSizeToOutgoingContext

func AppendMessageSizeToOutgoingContext(ctx context.Context, req Sizer) context.Context

func ComposeTapHandles

func ComposeTapHandles(handles []tap.ServerInHandle) tap.ServerInHandle

ComposeTapHandles allows multiple tap handles to be composed, since only one may be specified by gRPC server.

func ErrorToStatus

func ErrorToStatus(err error) (*status.Status, bool)

ErrorToStatus returns a *github.com/gogo/status.Status representation of err.

  • If err implements the method `GRPCStatus() *google.golang.org/grpc/status.Status` and `GRPCStatus()` does not return nil, or if err wraps a type satisfying this, Status from `GRPCStatus()` is converted to gogo Status, and returned. In that case, ok is true.

  • If err is or GRPCStatus() returns nil, a nil Status is returned and ok is false.

  • Otherwise, err is an error not compatible with this function. In this case, a nil Status is returned and ok is false.

func ErrorToStatusCode

func ErrorToStatusCode(err error) codes.Code

ErrorToStatusCode extracts gRPC status code from error and returns it.

  • If err is nil, codes.OK is returned.

  • If err implements (or wraps error that implements) the method `GRPCStatus() *google.golang.org/grpc/status.Status`, and `GRPCStatus()` returns a non-nil status, code from the status is returned.

  • Otherwise code.Unknown is returned.

func IsCanceled

func IsCanceled(err error) bool

IsCanceled checks whether an error comes from an operation being canceled.

func Status

func Status(errCode codes.Code, errMessage string, details ...proto.Message) *status.Status

Status creates a new a *github.com/gogo/status.Status with the given error code, error message and error details.

Types

type Check

type Check func(ctx context.Context) bool

Check is a function that determines if this gRPC application is healthy.

func WithManager

func WithManager(manager *services.Manager) Check

WithManager returns a new Check that tests if the managed services are healthy.

func WithShutdownRequested

func WithShutdownRequested(requested *atomic.Bool) Check

WithShutdownRequested returns a new Check that returns false when shutting down.

type ErrorCause

type ErrorCause int32
const (
	UNKNOWN_CAUSE                  ErrorCause = 0
	WRONG_CLUSTER_VALIDATION_LABEL ErrorCause = 1
)

func (ErrorCause) EnumDescriptor

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

func (ErrorCause) String

func (x ErrorCause) String() string

type ErrorDetails

type ErrorDetails struct {
	Cause ErrorCause `protobuf:"varint,1,opt,name=Cause,proto3,enum=grpcutil.ErrorCause" json:"Cause,omitempty"`
}

func (*ErrorDetails) Descriptor

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

func (*ErrorDetails) Equal

func (this *ErrorDetails) Equal(that interface{}) bool

func (*ErrorDetails) GetCause

func (m *ErrorDetails) GetCause() ErrorCause

func (*ErrorDetails) GoString

func (this *ErrorDetails) GoString() string

func (*ErrorDetails) Marshal

func (m *ErrorDetails) Marshal() (dAtA []byte, err error)

func (*ErrorDetails) MarshalTo

func (m *ErrorDetails) MarshalTo(dAtA []byte) (int, error)

func (*ErrorDetails) MarshalToSizedBuffer

func (m *ErrorDetails) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*ErrorDetails) ProtoMessage

func (*ErrorDetails) ProtoMessage()

func (*ErrorDetails) Reset

func (m *ErrorDetails) Reset()

func (*ErrorDetails) Size

func (m *ErrorDetails) Size() (n int)

func (*ErrorDetails) String

func (this *ErrorDetails) String() string

func (*ErrorDetails) Unmarshal

func (m *ErrorDetails) Unmarshal(dAtA []byte) error

func (*ErrorDetails) XXX_DiscardUnknown

func (m *ErrorDetails) XXX_DiscardUnknown()

func (*ErrorDetails) XXX_Marshal

func (m *ErrorDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ErrorDetails) XXX_Merge

func (m *ErrorDetails) XXX_Merge(src proto.Message)

func (*ErrorDetails) XXX_Size

func (m *ErrorDetails) XXX_Size() int

func (*ErrorDetails) XXX_Unmarshal

func (m *ErrorDetails) XXX_Unmarshal(b []byte) error

type HealthCheck

type HealthCheck struct {
	// contains filtered or unexported fields
}

HealthCheck fulfills the grpc_health_v1.HealthServer interface by ensuring each of the provided Checks indicates the application is healthy.

func NewHealthCheck

func NewHealthCheck(sm *services.Manager) *HealthCheck

NewHealthCheck returns a new HealthCheck for the provided service manager.

func NewHealthCheckFrom

func NewHealthCheckFrom(checks ...Check) *HealthCheck

NewHealthCheckFrom returns a new HealthCheck that uses each of the provided Checks.

func (*HealthCheck) Check

Check implements the grpc healthcheck.

func (*HealthCheck) List

List implements the grpc healthcheck.

func (*HealthCheck) Watch

Watch implements the grpc healthcheck.

type Operation

type Operation uint8

Operation defines the corresponding operations for a name resolution change.

const (
	// Add indicates a new address is added.
	Add Operation = iota
	// Delete indicates an existing address is deleted.
	Delete
)

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver handles name resolution for names following the DNS scheme.

func NewDNSResolver

func NewDNSResolver(logger log.Logger) (*Resolver, error)

NewDNSResolver creates a DNS Resolver that can resolve DNS names, and create watchers that poll the DNS server using the default frequency defined by defaultFreq.

func NewDNSResolverWithFreq

func NewDNSResolverWithFreq(freq time.Duration, logger log.Logger) (*Resolver, error)

NewDNSResolverWithFreq creates a DNS Resolver that can resolve DNS names, and create watchers that poll the DNS server using the frequency set by freq.

func (*Resolver) Resolve

func (r *Resolver) Resolve(target, service string) (Watcher, error)

Resolve creates a watcher that watches the SRV/hostname record resolution of the target.

If service is not empty, the watcher will first attempt to resolve an SRV record. If that fails, or service is empty, hostname record resolution is attempted instead. If target can be parsed as an IP address, the watcher will return it, and will not send any more updates afterwards.

type Sizer

type Sizer interface {
	Size() int
}

Sizer can return its size in bytes.

type Update

type Update struct {
	// Op indicates the operation of the update.
	Op Operation
	// Addr is the updated address. It is empty string if there is no address update.
	Addr string
	// Metadata is the updated metadata. It is nil if there is no metadata update.
	// Metadata is not required for a custom naming implementation.
	Metadata interface{}
}

Update defines a name resolution update. Notice that it is not valid having both empty string Addr and nil Metadata in an Update.

type Watcher

type Watcher interface {
	// Next blocks until an update or error happens. It may return one or more
	// updates. The first call should get the full set of the results. It should
	// return an error if and only if Watcher cannot recover.
	Next() ([]*Update, error)
	// Close closes the Watcher.
	Close()
}

Watcher watches for SRV updates on the specified target.

Jump to

Keyboard shortcuts

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