anchors

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnchorableTypes []anchorableType

AnchorableTypes contains all non-native types that can be anchorable. See AddAnchorableStructType to add a new type to it.

Functions

func AddAnchorableStructType

func AddAnchorableStructType(fn any) error

AddAnchorableStructType declares a struct type as anchorable. fn is a function allowing to return a unique and identifiable instance of the struct type.

fn has to have the following signature:

func (nextAnchor int) TYPE

TYPE is the struct type to make anchorable and nextAnchor is an index to allow to differentiate several instances of the same type.

For example, the time.Time type which is anchorable by default, is declared as:

AddAnchorableStructType(func (nextAnchor int) time.Time {
  return time.Unix(math.MaxInt64-1000424443-int64(nextAnchor), 42)
})

Just as a note, the 1000424443 constant allows to avoid to flirt with the math.MaxInt64 extreme limit and so avoid possible collision with real world values.

It returns an error if the provided fn is not a function or if it has not the expected signature (see above).

Types

type Info

type Info struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Info gathers all anchors information.

func NewInfo

func NewInfo() *Info

NewInfo returns a new instance of *Info.

func (*Info) AddAnchor

func (i *Info) AddAnchor(typ reflect.Type, op reflect.Value) (reflect.Value, error)

AddAnchor anchors a new operator op, with type typ then returns the anchor value.

func (*Info) DoAnchorsPersist

func (i *Info) DoAnchorsPersist() bool

DoAnchorsPersist returns true if anchors are persistent across tests.

func (*Info) ResetAnchors

func (i *Info) ResetAnchors(force bool)

ResetAnchors removes all anchors if persistence is disabled or force is true.

func (*Info) ResolveAnchor

func (i *Info) ResolveAnchor(v reflect.Value) (reflect.Value, bool)

ResolveAnchor checks whether the passed value matches an anchored operator or not. If yes, this operator is returned with true. If no, the value is returned as is with false.

func (*Info) SetAnchorsPersist

func (i *Info) SetAnchorsPersist(persist bool)

SetAnchorsPersist enables or disables anchors persistence.

Jump to

Keyboard shortcuts

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