Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
// Name is the name of the entry being changed.
Name string
// Old holds the original value, or nil if there was no original.
Old any
// New holds the new value, or nil if there is no new value.
New any
// Auto is true if New was created via a Factory.
Auto bool
}
Change represents a change to this routers contents.
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 WithOnChange ¶
WithOnChange registers a func that will be called whenever the contents of this router change. Changes include calls to Router.Add, Router.Remove, or Router.Get with a configured Factory.
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 any) any
// HoldsType returns true if this Router holds clients of the specified type.
HoldsType(client any) bool
// Remove removes and returns a named client.
Remove(name string) any
// 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) (any, error)
}
Router tracks a registry of gRPC clients. Typically used by code generated via the protoc-gen-router plugin.