Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 ¶
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 ¶
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.