Documentation ¶
Overview ¶
Package objectstore implements support for tracking a mapping of object references to and from their instance ID. It tracks objects by proxy of their memory address (i.e: pointer value), in order to avoid the pitfalls of go's standard object equality mechanism (which is also reflect.Value's equality mechanism) causing distinct instances appearing to be equal (including when used as keys to a map).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectStore ¶
type ObjectStore struct {
// contains filtered or unexported fields
}
ObjectStore tracks object instances for which an identifier has been associated. Object to instanceID association is tracked using the object memory address (aka pointer value) in order to not have issues with go's standard object equality rules (we need distinct - but possibly equal) object instances to be considered as separate entities for our purposes.
func (*ObjectStore) GetObject ¶
func (o *ObjectStore) GetObject(instanceID string) (value reflect.Value, found bool)
GetObject attempts to retrieve the object value associated with the given instanceID. Returns the existing value and a boolean informing whether a value was associated with this instanceID or not.
The GetObject method is safe to call with an instanceID that was never registered with the ObjectStore.
func (*ObjectStore) InstanceID ¶
func (o *ObjectStore) InstanceID(value reflect.Value) (instanceID string, found bool)
InstanceID attempts to determine the instanceID associated with the provided value, if any. Returns the existing instanceID and a boolean informing whether an instanceID was already found or not.
The InstanceID method is safe to call with values that are not track-able in an ObjectStore (i.e: non-pointer values, primitive values, etc...).
func (*ObjectStore) Register ¶
func (o *ObjectStore) Register(value reflect.Value, instanceID string) error
Register associates the provided value with the given instanceID. It also registers any anonymously embedded value (transitively) against the same instanceID, so that methods promoted from those resolve the correct instanceID, too.
Returns an error if the provided value is not a pointer value; if the value or any of it's (transitively) anonymous embeds have already been registered against a different instanceID; of if the provided instanceID was already associated to a different value.
The call is idempotent: calling Register again with the same value and instanceID does not result in an error.