pluggable

package
v0.0.0-...-949823d Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocketFolderEnvVar = "DAPR_COMPONENTS_SOCKETS_FOLDER"
)

Variables

This section is empty.

Functions

func AddServiceDiscoveryCallback

func AddServiceDiscoveryCallback(serviceName string, callbackFunc func(name string, dialer GRPCConnectionDialer))

AddServiceDiscoveryCallback adds a callback function that should be called when the given service was discovered.

func Discover

func Discover(ctx context.Context) error

Discover discover the pluggable components and callback the service discovery with the given component name and grpc dialer.

func GetSocketFolderPath

func GetSocketFolderPath() string

GetSocketFolderPath returns the shared unix domain socket folder path

func KitErrorFromGrpcError

func KitErrorFromGrpcError(err error) (error, bool)

func KitErrorFromGrpcErrorIgnore

func KitErrorFromGrpcErrorIgnore(err error) error

func KitErrorFromStatus

func KitErrorFromStatus(s *status.Status) (error, bool)

func MustStatusErrorFromKitError

func MustStatusErrorFromKitError(
	grpcCode codes.Code,
	httpCode int,
	message string,
	tag string,
	detail *errdetails.ErrorInfo,
) error

func NewConverterFunc

func NewConverterFunc(errorsConverters MethodErrorConverter) func(error) error

NewConverterFunc returns a function that maps from any error to a business error. if the error is unknown it is kept as is, otherwise a converter function will be used.

func SocketDial

func SocketDial(ctx context.Context, socket string, additionalOpts ...grpc.DialOption) (*grpc.ClientConn, error)

SocketDial creates a grpc connection using the given socket.

func StatusFromKitError

func StatusFromKitError(
	grpcCode codes.Code,
	httpCode int,
	message string,
	tag string,
	detail *errdetails.ErrorInfo,
) (*status.Status, error)

Types

type ErrorConverter

type ErrorConverter func(status.Status) error

func (ErrorConverter) Compose

func (outer ErrorConverter) Compose(inner ErrorConverter) ErrorConverter

Compose together two errors converters by applying the inner first and if the error was not converted, then it applies to the outer.

type GRPCClient

type GRPCClient interface {
	// Ping is for liveness purposes.
	Ping(ctx context.Context, in *proto.PingRequest, opts ...grpc.CallOption) (*proto.PingResponse, error)
}

GRPCClient is any client that supports common pluggable grpc operations.

type GRPCConnectionDialer

type GRPCConnectionDialer func(ctx context.Context, name string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func (GRPCConnectionDialer) WithOptions

func (g GRPCConnectionDialer) WithOptions(newOpts ...grpc.DialOption) GRPCConnectionDialer

WithOptions returns a new connection dialer that adds the new options to it.

type GRPCConnector

type GRPCConnector[TClient GRPCClient] struct {
	// Context is the component shared context
	Context context.Context
	// Cancel is used for cancelling inflight requests
	Cancel context.CancelFunc
	// Client is the proto client.
	Client TClient
	// contains filtered or unexported fields
}

GRPCConnector is a connector that uses underlying gRPC protocol for common operations.

func NewGRPCConnector

func NewGRPCConnector[TClient GRPCClient](socket string, factory func(grpc.ClientConnInterface) TClient) *GRPCConnector[TClient]

NewGRPCConnector creates a new grpc connector for the given client factory and socket file, using the default socket dialer.

func NewGRPCConnectorWithDialer

func NewGRPCConnectorWithDialer[TClient GRPCClient](dialer GRPCConnectionDialer, factory func(grpc.ClientConnInterface) TClient) *GRPCConnector[TClient]

NewGRPCConnectorWithDialer creates a new grpc connector for the given client factory and dialer.

func (*GRPCConnector[TClient]) Close

func (g *GRPCConnector[TClient]) Close() error

Close closes the underlying gRPC connection and cancel all inflight requests.

func (*GRPCConnector[TClient]) Dial

func (g *GRPCConnector[TClient]) Dial(name string) error

Dial opens a grpcConnection and creates a new client instance.

func (*GRPCConnector[TClient]) Ping

func (g *GRPCConnector[TClient]) Ping() error

Ping pings the grpc component. It uses "WaitForReady" avoiding failing in transient failures.

type MethodErrorConverter

type MethodErrorConverter map[codes.Code]ErrorConverter

MethodErrorConverter represents a simple map that maps from a grpc statuscode to a domain-level error.

func (MethodErrorConverter) Merge

Jump to

Keyboard shortcuts

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