identifiers

package
v0.0.0-...-f4b31ea Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

identifiers contains strategies for converting concrete objects to store in Karte (actions and observations) into identities. There are two strategies in this package.

ProdStrategy -- Uses the current time and an entropy source. NaiveStrategy -- Has a global in-memory counter and produces entity1, entity2, ...

Index

Constants

View Source
const IDVersion = "zzzz"

The IDVersion must be four bytes long. Please record all previously used ID versions here. It must use the character set [A-Z0-9a-z].

- zzzz (current) - zzzy (next) - zzzx (next-next)

View Source
const VersionPrefixLength = 4

The first four bytes of a Karte action identifier are the version.

Variables

This section is empty.

Functions

func GetIDVersion

func GetIDVersion(serialized string) string

GetIDVersion gets the id version from a serialized ID.

func MakeRawID

func MakeRawID(t time.Time, disambiguation uint32) (string, error)

MakeRawID makes an ID for a given entity by taking a time (the creation or ingestion time, depending on the kind). The uuidSuffix is a uuid that will be used as a disambiguation suffix.

func Use

func Use(ctx context.Context, strategy Strategy) context.Context

Use produces a new context with the given ID generation strategy as the strategy.

Types

type Strategy

type Strategy interface {
	// IDForAction takes an action and returns an ID.
	IDForAction(ctx context.Context, action *kartepb.Action) (string, error)

	// IDForObservation takes an observation and returns an ID.
	IDForObservation(ctx context.Context, observation *kartepb.Observation) (string, error)
}

Strategy controls how to convert an entity or record into a UUID that is used as a datastore key.

func Get

func Get(ctx context.Context) Strategy

Get gets the current strategy from the context.

func NewDefault

func NewDefault() Strategy

NewDefault instantiates the default strategy, which is the production strategy.

func NewNaive

func NewNaive() Strategy

NewNaive creates a new naive strategy.

Jump to

Keyboard shortcuts

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