selector

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPriority = int(100)
)

Variables

View Source
var (
	ErrForwardLoop       = errors.Base("selector forward loop detected")
	ErrHasNoSelector     = errors.Base("has no selector")
	ErrNoMethodExists    = errors.Base("no method by this name exists")
	ErrNoMethodSpecified = errors.Base("no method specified")
	ErrNoMethodToWrap    = errors.Base("no method to wrap")
	ErrReferenceParse    = errors.Base("reference parse failure")
	ErrSelectorNotFound  = errors.Base("no method for selector")
	ErrSelectorPanic     = errors.Base("panic during selector method")
	ErrUnresolved        = errors.Base("unresolved selector")
)

Functions

func DisableTrace

func DisableTrace()

func DumpIntrospectableInfo

func DumpIntrospectableInfo(obj Introspectable) string

func EnableTrace

func EnableTrace()

func SetTraceOutput

func SetTraceOutput(out *os.File)

func Trace

func Trace(format string, args ...any)

func TraceWithWrapper

func TraceWithWrapper(isWrapped bool, format string, args ...any)

Types

type AuxiliaryMethod

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

type Entry

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

Selector table entry.

type Introspectable

type Introspectable interface {
	responder.Respondable

	// Return a list of selectors.
	Selectors() []string

	// Return a list of sorted selectors
	SortedSelectors() []string

	// Return a list of methods that the object can respond to.
	Methods() *Table

	// Does the object conform to the given protocol?
	ConformsTo(protocol string) bool

	// List all protocols for which the object claims conformity.
	ListProtocols() []string

	// Return a map of metadata for a selector
	MetadataForSelector(string) (map[string]string, error)
}

Objects that implement these methods are considered `introspectable` and are deemed capable of being asked to describe themselves in various ways.

type Method

Selector method function signature type.

type Namespace

type Namespace struct {
	Uses   []*Package
	Shadow map[string]bool
}

func (*Namespace) Dispatch

func (ns *Namespace) Dispatch(
	reg *Registry,
	raw string, target responder.Respondable, evt events.Event,
) (events.Event, bool, string)

func (*Namespace) Resolve

func (ns *Namespace) Resolve(reg *Registry, ref Ref) (ResolveResult, bool)

Resolve a reference.

type Package

type Package struct {
	Name  string
	Table *Table
	// contains filtered or unexported fields
}

Packages.

A package provides a table of selectors, aliases, and defaults.

func NewPackage

func NewPackage(name string) *Package

func (*Package) Alias

func (pkg *Package) Alias(alias, target string) bool

Create an alias that maps alias to target.

func (*Package) Export

func (pkg *Package) Export(name string) bool

Export a selector.

func (*Package) GetDefault

func (pkg *Package) GetDefault(op string) (string, bool)

Returns the default for the given operation.

func (*Package) IsExported

func (pkg *Package) IsExported(name string) bool

Is the given selector exported?

func (*Package) ResolveAlias

func (pkg *Package) ResolveAlias(name string) string

Resolve a selector.

If the specified selector is an alias, then its target is returned.

func (*Package) SetDefault

func (pkg *Package) SetDefault(operator, name string) bool

Sets a default selector.

func (*Package) Unexport

func (pkg *Package) Unexport(name string)

type Ref

type Ref struct {
	Package  string // Package name.
	Name     string // Name.
	Version  string // Version, e.g. "v1", "v1.2" et al
	Internal bool   // If true, then thing is package internal.
}

func ParseRef

func ParseRef(ref string) (Ref, bool)

Parse a reference.

Supports:

name
name@version
package:name
package::name
package:name@version
package::name@version

type Registry

type Registry struct {
	GlobalDefault *Package
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AddPackage

func (r *Registry) AddPackage(pkg *Package)

func (*Registry) GetPackage

func (r *Registry) GetPackage(name string) (*Package, bool)

type ResolveResult

type ResolveResult struct {
	Pkg   *Package
	Table *Table
	Name  string
	Why   string
}

func (ResolveResult) String

func (r ResolveResult) String() string

type Respondable

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

func NewRespondable

func NewRespondable(name, typeName string) *Respondable

func (*Respondable) AddProtocol

func (sr *Respondable) AddProtocol(name string)

func (*Respondable) ConformsTo

func (sr *Respondable) ConformsTo(name string) bool

func (*Respondable) Invoke

func (sr *Respondable) Invoke(evt events.Event) events.Event

func (*Respondable) ListProtocols

func (sr *Respondable) ListProtocols() []string

func (*Respondable) MetadataForSelector

func (sr *Respondable) MetadataForSelector(selector string) (map[string]string, error)

func (*Respondable) Methods

func (sr *Respondable) Methods() *Table

func (*Respondable) Name

func (sr *Respondable) Name() string

func (*Respondable) RespondsTo

func (sr *Respondable) RespondsTo(evt events.Event) bool

func (*Respondable) Selectors

func (sr *Respondable) Selectors() []string

func (*Respondable) SortedSelectors

func (sr *Respondable) SortedSelectors() []string

func (*Respondable) Type

func (sr *Respondable) Type() string

type SelectorError

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

Selector error event.

NOTE: `golangci-lint` will want this to be called `Error', and that is not what we want. This is an explicit event, not to be confused with `events.Error`.

func NewSelectorError

func NewSelectorError(err error) *SelectorError

func (*SelectorError) Error

func (e *SelectorError) Error() error

func (*SelectorError) Selector

func (e *SelectorError) Selector() string

func (*SelectorError) String

func (e *SelectorError) String() string

func (*SelectorError) When

func (e *SelectorError) When() time.Time

type SelectorEvent

type SelectorEvent interface {
	events.Event

	Selector() string
}

This interface represents a Selector-specific event.

NOTE: `golangci-lint` will want this to be called `Event`. this is a bad idea because this type is explicitly for selector-specific events, and should not be confused with `events.Event`.

type Table

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

Map selector names to method implementations.

func NewTable

func NewTable() *Table

func (*Table) AddAfter

func (st *Table) AddAfter(selector string, method Method) error

func (*Table) AddAfterWithPriority

func (st *Table) AddAfterWithPriority(priority int, selector string, method Method) error

func (*Table) AddBefore

func (st *Table) AddBefore(selector string, method Method) error

func (*Table) AddBeforeWithPriority

func (st *Table) AddBeforeWithPriority(priority int, selector string, method Method) error

func (*Table) AllMetadata

func (st *Table) AllMetadata() map[string]map[string]string

func (*Table) Get

func (st *Table) Get(name string) (*Entry, bool)

Return an entry for a selector.

func (*Table) HasSelector

func (st *Table) HasSelector(selector string) bool

Check whether a selector is defined.

func (*Table) InvokeSelector

func (st *Table) InvokeSelector(sel string, tgt responder.Respondable, evt events.Event) (events.Event, bool)

func (*Table) InvokeSelectorAsync

func (st *Table) InvokeSelectorAsync(
	ctx context.Context,
	sel string,
	tgt responder.Respondable, evt events.Event,
) <-chan events.Event

func (*Table) ListMetadata

func (st *Table) ListMetadata(selector string) (map[string]string, error)

func (*Table) Metadata

func (st *Table) Metadata(selector string) (metadata.Metadata, error)

func (*Table) MustMetadata

func (st *Table) MustMetadata(selector string) metadata.Metadata

func (*Table) Register

func (st *Table) Register(selector string, method Method)

Register a method for a selector.

func (*Table) SetDefault

func (st *Table) SetDefault(selector string)

func (*Table) SetMaxForwardDepth

func (st *Table) SetMaxForwardDepth(val int)

func (*Table) SetPrimary

func (st *Table) SetPrimary(selector string, method Method) (Method, error)

func (*Table) Unregister

func (st *Table) Unregister(selector string)

Jump to

Keyboard shortcuts

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