Documentation
¶
Index ¶
- Constants
- Variables
- func AssureUpdater(attrs AttributesContext, u Updater)
- func RegisterAttributeType(name string, typ AttributeType, short ...string) error
- func RegisterSetupHandler(h SetupHandler)
- func SetupContext[C Context](mode BuilderMode, ctx C) C
- func SetupElement[T ElementCopyable[T]](mode BuilderMode, target *T, create ElementCreator[T], def T) error
- type AttributeFactory
- type AttributeScheme
- type AttributeType
- type Attributes
- type AttributesContext
- type Builder
- type BuilderMode
- type Context
- type ContextIdentity
- type ContextProvider
- type Converter
- type DefaultAttributeType
- type Delegates
- type ElementCopyable
- type ElementCreator
- type InternalContext
- type KnownTypes
- type ObjectKey
- type Session
- type SessionBase
- type SetupHandler
- type SetupHandlerFunction
- type SetupHandlerRegistry
- type UpdateFunc
- type Updater
Constants ¶
const CONTEXT_TYPE = "attributes" + OCM_CONTEXT_SUFFIX
CONTEXT_TYPE is the global type for an attribute context.
const OCM_CONTEXT_SUFFIX = ".context" + common.OCM_TYPE_GROUP_SUFFIX
Variables ¶
var DefaultAttributeScheme = NewDefaultAttributeScheme()
var DefaultContext = NewWithActions(nil, handlers.DefaultRegistry())
DefaultContext is the default context initialized by init functions.
Functions ¶
func AssureUpdater ¶
func AssureUpdater(attrs AttributesContext, u Updater)
AssureUpdater is used to assure the existence of an updater in a root context if a config context is down the context hierarchy. This method SHOULD only be called by a config context.
func RegisterAttributeType ¶
func RegisterAttributeType(name string, typ AttributeType, short ...string) error
func RegisterSetupHandler ¶ added in v0.4.1
func RegisterSetupHandler(h SetupHandler)
func SetupContext ¶ added in v0.4.1
func SetupContext[C Context](mode BuilderMode, ctx C) C
func SetupElement ¶
func SetupElement[T ElementCopyable[T]](mode BuilderMode, target *T, create ElementCreator[T], def T) error
Types ¶
type AttributeFactory ¶
type AttributeFactory func(Context) interface{}
AttributeFactory is used to atomicly create a new attribute for a context.
type AttributeScheme ¶
type AttributeScheme interface { Register(name string, typ AttributeType, short ...string) error Decode(attr string, data []byte, unmarshaler runtime.Unmarshaler) (interface{}, error) Encode(attr string, v interface{}, marshaller runtime.Marshaler) ([]byte, error) Convert(attr string, v interface{}) (interface{}, error) GetType(attr string) (AttributeType, error) AddKnownTypes(scheme AttributeScheme) Shortcuts() common.Properties KnownTypes() KnownTypes KnownTypeNames() []string }
func NewDefaultAttributeScheme ¶ added in v0.4.1
func NewDefaultAttributeScheme() AttributeScheme
type AttributeType ¶
type Attributes ¶
type Attributes interface { GetAttribute(name string, def ...interface{}) interface{} SetAttribute(name string, value interface{}) error SetEncodedAttribute(name string, data []byte, unmarshaller runtime.Unmarshaler) error GetOrCreateAttribute(name string, creator AttributeFactory) interface{} }
func NewAttributes ¶
func NewAttributes(ctx Context, parent Attributes, updater *Updater) Attributes
type AttributesContext ¶
func ForContext ¶
func ForContext(ctx context.Context) AttributesContext
ForContext returns the Context to use for context.Context. This is either an explicit context or the default context.
func New ¶
func New(parentAttrs Attributes) AttributesContext
New provides a root attribute context.
func NewWithActions ¶ added in v0.3.0
func NewWithActions(parentAttrs Attributes, actions handlers.Registry) AttributesContext
type Builder ¶ added in v0.3.0
type Builder struct {
// contains filtered or unexported fields
}
func (Builder) New ¶ added in v0.3.0
func (b Builder) New(m ...BuilderMode) Context
func (Builder) WithActionHandlers ¶ added in v0.3.0
func (Builder) WithAttributes ¶ added in v0.3.0
func (b Builder) WithAttributes(paranetAttr Attributes) Builder
type BuilderMode ¶
type BuilderMode int
BuilderMode controls the handling of unset information in the builder configuration when calling the New method.
const ( // MODE_SHARED uses the default contexts for unset nested context types. MODE_SHARED BuilderMode = iota // MODE_DEFAULTED uses dedicated context instances configured with the // context type specific default registrations. MODE_DEFAULTED // MODE_EXTENDED uses dedicated context instances configured with // context type registrations extending the default registrations. MODE_EXTENDED // MODE_CONFIGURED uses dedicated context instances configured with the // context type registrations configured with the actual state of the // default registrations. MODE_CONFIGURED // MODE_INITIAL uses completely new contexts for unset nested context types // and initial registrations. MODE_INITIAL )
func Mode ¶
func Mode(m ...BuilderMode) BuilderMode
func (BuilderMode) String ¶
func (m BuilderMode) String() string
type Context ¶
type Context interface { ContextProvider Delegates // GetType returns the context type GetType() string GetId() ContextIdentity // BindTo binds the context to a context.Context and makes it // retrievable by a ForContext method BindTo(ctx context.Context) context.Context GetAttributes() Attributes }
Context describes a common interface for a data context used for a dedicated purpose. Such has a type and always specific attribute store. Every Context can be bound to a context.Context.
func ForContextByKey ¶
ForContextByKey retrieves the context for a given key to be used for a context.Context. If not defined, it returns the given default context and false.
func WithContext ¶
WithContext create a new Context bound to a context.Context.
type ContextIdentity ¶ added in v0.3.0
type ContextIdentity = finalizer.ObjectIdentity
type ContextProvider ¶
type ContextProvider interface { // AttributesContext returns the shared attributes AttributesContext() AttributesContext }
type Converter ¶ added in v0.4.1
type Converter interface {
Convert(interface{}) (interface{}, error)
}
Converter is an optional interface an AttributeType can implement to normalize an attribute value. It is called by the Attributes.SetAttribute method.
type DefaultAttributeType ¶
type DefaultAttributeType struct{}
type Delegates ¶ added in v0.3.0
type Delegates interface { ocmlog.LogProvider handlers.ActionsProvider }
Delegates is the interface for common Context features, which might be delegated to aggregated contexts.
type ElementCopyable ¶
type ElementCopyable[T any] interface { comparable Copy() T }
type ElementCreator ¶
type ElementCreator[T any] func(base ...T) T
type InternalContext ¶ added in v0.3.0
type InternalContext interface { Context finalizer.RecorderProvider }
func NewContextBase ¶
func NewContextBase(eff Context, typ string, key interface{}, parentAttrs Attributes, delegates Delegates) InternalContext
NewContextBase creates a context base implementation supporting context attributes and the binding to a context.Context.
type KnownTypes ¶
type KnownTypes map[string]AttributeType
KnownTypes is a set of known type names mapped to appropriate object decoders.
func (KnownTypes) Copy ¶
func (t KnownTypes) Copy() KnownTypes
Copy provides a copy of the actually known types.
func (KnownTypes) TypeNames ¶
func (t KnownTypes) TypeNames() []string
TypeNames return a sorted list of known type names.
type Session ¶
type Session interface { Closer(closer io.Closer, extra ...interface{}) (io.Closer, error) GetOrCreate(key interface{}, creator func(SessionBase) Session) Session AddCloser(closer io.Closer, callbacks ...accessio.CloserCallback) io.Closer Close() error IsClosed() bool }
Session is a context keeping track of objects requiring a close after final use. When closing a session all subsequent objects will be closed in the opposite order they are added. Added closers may be closed prio to the session without causing errors.
func GetOrCreateSubSession ¶
func GetOrCreateSubSession(s Session, key interface{}, creator func(SessionBase) Session) Session
func NewSession ¶
func NewSession() Session
type SessionBase ¶
type SetupHandler ¶ added in v0.4.1
type SetupHandler interface {
Setup(mode BuilderMode, ctx Context)
}
SetupHandler is a handler, which can be registered by an arbitrary context part used to setup this parts for a new context. For example, a typical use case is setup a default value for a context attribute. The handler may consider the context creation mode to determine the initial content or structure of the context part.
type SetupHandlerFunction ¶ added in v0.4.1
type SetupHandlerFunction func(mode BuilderMode, ctx Context)
SetupHandlerFunction is a function usable as SetupHandler.
func (SetupHandlerFunction) Setup ¶ added in v0.4.1
func (f SetupHandlerFunction) Setup(mode BuilderMode, ctx Context)
type SetupHandlerRegistry ¶ added in v0.4.1
type SetupHandlerRegistry interface { Register(h SetupHandler) Setup(mode BuilderMode, ctx Context) }
SetupHandlerRegistry is used to register and execute SetupHandler for a freshly created context.
type UpdateFunc ¶
type UpdateFunc func() error
func (UpdateFunc) Update ¶
func (u UpdateFunc) Update() error