register

package
v1.13.14-0.4.0.rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package register provides functionality for optional registration of types.

Index

Constants

This section is empty.

Variables

View Source
var ErrReRegistration = errors.New("re-registration")

ErrReRegistration is returned on all but the first of calls to AtMostOnce.Register.

Functions

This section is empty.

Types

type AtMostOnce

type AtMostOnce[T any] struct {
	// contains filtered or unexported fields
}

An AtMostOnce allows zero or one registration of a T.

func (*AtMostOnce[T]) Get

func (o *AtMostOnce[T]) Get() T

Get returns the registered value. It MUST NOT be called before AtMostOnce.Register.

func (*AtMostOnce[T]) MustRegister

func (o *AtMostOnce[T]) MustRegister(v T)

MustRegister is equivalent to AtMostOnce.Register, panicking on error.

func (*AtMostOnce[T]) Register

func (o *AtMostOnce[T]) Register(v T) error

Register registers `v` or returns ErrReRegistration if already called.

func (*AtMostOnce[T]) Registered

func (o *AtMostOnce[T]) Registered() bool

Registered reports whether AtMostOnce.Register has been called.

func (*AtMostOnce[T]) TempClear

func (o *AtMostOnce[T]) TempClear(fn func() error) error

TempClear calls `fn`, clearing any registered `T`, but only for the life of the call. It is not threadsafe.

It is valid to call this method with or without a prior call to AtMostOnce.Register.

func (*AtMostOnce[T]) TempOverride

func (o *AtMostOnce[T]) TempOverride(with T, fn func() error) error

TempOverride calls `fn`, overriding any registered `T`, but only for the life of the call. It is not threadsafe.

It is valid to call this method with or without a prior call to AtMostOnce.Register.

func (*AtMostOnce[T]) TestOnlyClear

func (o *AtMostOnce[T]) TestOnlyClear()

TestOnlyClear clears any previously registered value, returning `o` to its default state. It panics if called from a non-testing call stack.

Jump to

Keyboard shortcuts

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