grpcutil

package
v0.0.0-...-de40865 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 34

Documentation

Index

Constants

View Source
const MetadataMessageSize = "message-size"

MetadataMessageSize is grpc metadata key for message size.

Variables

This section is empty.

Functions

func AppendMessageSizeToOutgoingContext

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

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.

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