pluggable

package
v0.0.0-...-94fc2ed Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddServiceDiscoveryCallback

func AddServiceDiscoveryCallback(serviceName string, callback CallbackFunc)

AddServiceDiscoveryCallback register callback function, not concurrent secure

func GetServiceDiscoveryMapper

func GetServiceDiscoveryMapper() map[string]CallbackFunc

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 TestServerFor

func TestServerFor[TServer any, TClient any](registersvc func(grpc.ServiceRegistrar, TServer), clientFactory func(grpc.ClientConnInterface) TClient) func(svc TServer) (client TClient, cleanup func(), err error)

TestServerFor returns a grpcServer factory that bootstraps a grpcserver backed by a buf connection (in memory), and returns the given clientFactory instance to communicate with it. it also provides cleanup function for close the grpcserver and client connection.

usage,
	serverFactory := TestServerFor(proto.RegisterMyService, proto.NewMyServiceClient)
 	client, cleanup, err := serverFactory(&your_service{})
	require.NoError(t, err)
	defer cleanup()

func TestSocketServerFor

func TestSocketServerFor[TServer any, TClient any](registersvc func(grpc.ServiceRegistrar, TServer), clientFactory func(GRPCConnectionDialer) TClient) func(svc TServer) (client TClient, cleanup func(), err error)

TestSocketServerFor returns a grpcServer factory that bootstraps a grpcserver backed by grpc socket, and returns the given clientFactory instance to communicate with it. it also provides cleanup function for close the grpcserver and client connection. The closure of dial needs to be handled by the user themselves

usage,
	serverFactory := TestSocketServerFor(proto.RegisterMyService, NewGRPCHello) // (func NewGRPCHello(dialer pluggable.GRPCConnectionDialer) *grpcHello)
 	client, cleanup, err := serverFactory(&your_service{})
	require.NoError(t, err)
	defer cleanup()

func ToProtoComponentRef

func ToProtoComponentRef(config *ref.ComponentRefConfig) *pb.ComponentRefConfig

func ToProtoConfig

func ToProtoConfig(config ref.Config) *pb.Config

func ToProtoSecretRef

func ToProtoSecretRef(secrets []*ref.SecretRefConfig) []*pb.SecretRefConfig

Types

type CallbackFunc

type CallbackFunc func(compType string, dialer GRPCConnectionDialer) Component

type Component

type Component interface{}

type GRPCConnectionDialer

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

func SocketDialer

func SocketDialer(socket string, additionalOpts ...grpc.DialOption) GRPCConnectionDialer

SocketDialer creates a dialer for the given socket.

func (GRPCConnectionDialer) WithOptions

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

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

Jump to

Keyboard shortcuts

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