parent

package
v0.0.0-...-084e4ab Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultModelOptions = []resource.Option{
	resource.WithClock(clock.Real()),
}

DefaultModelOptions holds the default options for the model.

Functions

func WithChildrenOption

func WithChildrenOption(opts ...resource.Option) resource.Option

WithChildrenOption configures the children resource of the model.

func WithInitialChildren

func WithInitialChildren(children ...*traits.Child) resource.Option

WithInitialChildren returns an option that configures the model to initialise with the given children. Can be called multiple times to add more children. Panics if any child has no name. Panics if any child's traits are not sorted.

func WithParentApiClientFactory

func WithParentApiClientFactory(f func(name string) (traits.ParentApiClient, error)) router.Option

WithParentApiClientFactory instructs the router to create a new client the first time Get is called for that name.

func WithParentInfoClientFactory

func WithParentInfoClientFactory(f func(name string) (traits.ParentInfoClient, error)) router.Option

WithParentInfoClientFactory instructs the router to create a new client the first time Get is called for that name.

func WrapApi

WrapApi adapts a traits.ParentApiServer and presents it as a traits.ParentApiClient

func WrapInfo

WrapInfo adapts a traits.ParentInfoServer and presents it as a traits.ParentInfoClient

Types

type ApiRouter

type ApiRouter struct {
	traits.UnimplementedParentApiServer

	router.Router
}

ApiRouter is a traits.ParentApiServer that allows routing named requests to specific traits.ParentApiClient

func NewApiRouter

func NewApiRouter(opts ...router.Option) *ApiRouter

func (*ApiRouter) Add

func (r *ApiRouter) Add(name string, client any) any

Add extends Router.Add to panic if client is not of type traits.ParentApiClient.

func (*ApiRouter) AddParentApiClient

func (r *ApiRouter) AddParentApiClient(name string, client traits.ParentApiClient) traits.ParentApiClient

func (*ApiRouter) GetParentApiClient

func (r *ApiRouter) GetParentApiClient(name string) (traits.ParentApiClient, error)

func (*ApiRouter) HoldsType

func (r *ApiRouter) HoldsType(client any) bool

func (*ApiRouter) ListChildren

func (*ApiRouter) PullChildren

func (*ApiRouter) Register

func (r *ApiRouter) Register(server *grpc.Server)

func (*ApiRouter) RemoveParentApiClient

func (r *ApiRouter) RemoveParentApiClient(name string) traits.ParentApiClient

type InfoRouter

type InfoRouter struct {
	traits.UnimplementedParentInfoServer

	router.Router
}

InfoRouter is a traits.ParentInfoServer that allows routing named requests to specific traits.ParentInfoClient

func NewInfoRouter

func NewInfoRouter(opts ...router.Option) *InfoRouter

func (*InfoRouter) Add

func (r *InfoRouter) Add(name string, client any) any

Add extends Router.Add to panic if client is not of type traits.ParentInfoClient.

func (*InfoRouter) AddParentInfoClient

func (r *InfoRouter) AddParentInfoClient(name string, client traits.ParentInfoClient) traits.ParentInfoClient

func (*InfoRouter) GetParentInfoClient

func (r *InfoRouter) GetParentInfoClient(name string) (traits.ParentInfoClient, error)

func (*InfoRouter) HoldsType

func (r *InfoRouter) HoldsType(client any) bool

func (*InfoRouter) Register

func (r *InfoRouter) Register(server *grpc.Server)

func (*InfoRouter) RemoveParentInfoClient

func (r *InfoRouter) RemoveParentInfoClient(name string) traits.ParentInfoClient

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model models a collection of children.

func NewModel

func NewModel(opts ...resource.Option) *Model

func (*Model) AddChild

func (m *Model) AddChild(child *traits.Child)

AddChild inserts a child into this model. If a child with the given Child.Name already exists, no changes will be made. Panics if child.Traits are not sorted in ascending order, required by AddChildTrait.

func (*Model) AddChildTrait

func (m *Model) AddChildTrait(name string, traitName ...trait.Name) (child *traits.Child, created bool)

AddChildTrait ensures that a child with the given name and list of trait names exists in this model. If no child with the given name is already know, one will be created. If a child is already known with the given name, its traits will be unioned with the given trait names.

func (*Model) ListChildren

func (m *Model) ListChildren() []*traits.Child

ListChildren returns a slice of all known Child instances.

func (*Model) PullChildren

func (m *Model) PullChildren(ctx context.Context, opts ...resource.ReadOption) <-chan *traits.PullChildrenResponse_Change

PullChildren returns a chan that will emit when changes are made to the known children of this model.

func (*Model) RemoveChildByName

func (m *Model) RemoveChildByName(name string, opts ...resource.WriteOption) (*traits.Child, error)

RemoveChildByName removes a child from this model matching the given name.

func (*Model) RemoveChildTrait

func (m *Model) RemoveChildTrait(name string, traitName ...trait.Name) *traits.Child

RemoveChildTrait ensures that the named child no longer mentions they support the given trait names. If no child exists with the given name then nil will be returned.

type ModelOption

type ModelOption interface {
	resource.Option
	// contains filtered or unexported methods
}

ModelOption defined the base type for all options that apply to this traits model.

type ModelServer

type ModelServer struct {
	traits.UnimplementedParentApiServer
	// contains filtered or unexported fields
}

ModelServer exposes Model as a traits.ParentApiServer.

func NewModelServer

func NewModelServer(model *Model) *ModelServer

func (*ModelServer) ListChildren

func (*ModelServer) PullChildren

func (*ModelServer) Unwrap

func (s *ModelServer) Unwrap() any

Jump to

Keyboard shortcuts

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