router

package
v0.0.0-...-3a0ac50 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: AGPL-3.0 Imports: 3 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory func(string) (interface{}, error) // returns the type MyServiceClient

type OnCommit

type OnCommit func(name string, client interface{})

OnCommit is a callback function for use in WithOnCommit.

type Option

type Option func(r *router)

func WithFactory

func WithFactory(f Factory) Option

WithFactory configures a Router to call the given function when Get is called and no existing client is known. Prefer using the generated WithMyServiceClientFactory methods in the trait packages. The given factory may be called multiple times with the same name if concurrent access is performed. Only one returned client will be remembered. Use WithOnCommit if you need to trigger side effects as part of your client creation.

func WithFallback

func WithFallback(f Factory) Option

WithFallback configures a Router to ask the given function when Get is called and no existing client is known. If WithFallback and WithFactory are both configured, WithFallback will be called first, only using WithFactory if WithFallback returns nil or an error.

func WithOnCommit

func WithOnCommit(onCommit OnCommit) Option

WithOnCommit registers a func that will be called with the value remembered as part of a WithFactory Factory call. Use this if you want to register or otherwise setup side effects for Factory created entries.

type Router

type Router interface {
	// Add adds a named client to this Router.
	// Add returns the old client associated with this name, or nil if there wasn't one.
	// If HoldsType returns false for the given client, this will panic.
	Add(name string, client interface{}) interface{}
	// HoldsType returns true if this Router holds clients of the specified type.
	HoldsType(client interface{}) bool
	// Remove removes and returns a named client.
	Remove(name string) interface{}
	// Has returns true if this Router has a client with the given name.
	Has(name string) bool
	// Get returns the client for the given name.
	// An error will be returned if no such client exists.
	Get(name string) (interface{}, error)
}

Router tracks a registry of gRPC clients. Typically used by code generated via the protoc-gen-router plugin.

func NewRouter

func NewRouter(opts ...Option) Router

NewRouter creates a new instance of Router with the given options.

Jump to

Keyboard shortcuts

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