identity

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Anonymous is an Identity that can be used when identity doesn't matter.
	Anonymous = StringIdentity("__anonymous")

	// GenghisKhan is an Identity everyone relates to.
	GenghisKhan = StringIdentity("__genghiskhan")
)

Variables

This section is empty.

Functions

func CleanString

func CleanString(s string) string

CleanString cleans s to be suitable as an identifier.

func HashString

func HashString(vs ...any) string

HashString returns a hash from the given elements. It will panic if the hash cannot be calculated. Note that this hash should be used primarily for identity, not for change detection as it in the more complex values (e.g. Page) will not hash the full content.

func HashUint64

func HashUint64(vs ...any) uint64

HashUint64 returns a hash from the given elements. It will panic if the hash cannot be calculated. Note that this hash should be used primarily for identity, not for change detection as it in the more complex values (e.g. Page) will not hash the full content.

func WalkIdentitiesShallow

func WalkIdentitiesShallow(v any, cb func(level int, id Identity) bool)

WalkIdentitiesShallow will not walk into a Manager's Identities. See WalkIdentitiesDeep. cb is called for every Identity found and returns whether to terminate the walk.

Types

type DependencyManagerProvider

type DependencyManagerProvider interface {
	GetDependencyManager() Manager
}

type FindFirstManagerIdentityProvider

type FindFirstManagerIdentityProvider interface {
	Identity
	FindFirstManagerIdentity() ManagerIdentity
}

func NewFindFirstManagerIdentityProvider

func NewFindFirstManagerIdentityProvider(m Manager, id Identity) FindFirstManagerIdentityProvider

type Finder

type Finder struct {
	// contains filtered or unexported fields
}

Finder finds identities inside another.

func NewFinder

func NewFinder(cfg FinderConfig) *Finder

NewFinder creates a new Finder. This is a thread safe implementation with a cache.

func (*Finder) Contains

func (f *Finder) Contains(id, in Identity, maxDepth int) FinderResult

Contains returns whether in contains id.

type FinderConfig

type FinderConfig struct {
	// Match exact matches only.
	Exact bool
}

FinderConfig provides configuration for the Finder. Note that we by default will use a strategy where probable matches are good enough. The primary use case for this is to identity the change set for a given changed identity (e.g. a template), and we don't want to have any false negatives there, but some false positives are OK. Also, speed is important.

type FinderResult

type FinderResult int
const (
	FinderNotFound FinderResult = iota
	FinderFoundOneOfManyRepetition
	FinderFoundOneOfMany
	FinderFound
)

type ForEeachIdentityByNameProvider

type ForEeachIdentityByNameProvider interface {
	// ForEeachIdentityByName calls cb for each Identity that relates to name.
	// If cb returns true, the iteration is terminated.
	ForEeachIdentityByName(name string, cb func(id Identity) bool)
}

ForEeachIdentityByNameProvider provides a way to look up identities by name.

type ForEeachIdentityProvider

type ForEeachIdentityProvider interface {
	// ForEeachIdentityProvider calls cb for each Identity.
	// If cb returns true, the iteration is terminated.
	// The return value is whether the iteration was terminated.
	ForEeachIdentity(cb func(id Identity) bool) bool
}

ForEeachIdentityProvider provides a way iterate over identities.

type Identities

type Identities map[Identity]bool

Identities stores identity providers.

func (Identities) AsSlice

func (ids Identities) AsSlice() []Identity

func (Identities) String

func (ids Identities) String() string

type Identity

type Identity interface {
	IdentifierBase() string
}

Identity represents a thing in Hugo (a Page, a template etc.) Any implementation must be comparable/hashable.

func FirstIdentity

func FirstIdentity(v any) Identity

FirstIdentity returns the first Identity in v, Anonymous if none found

func Unwrap

func Unwrap(id Identity) Identity

type IdentityGroupProvider

type IdentityGroupProvider interface {
	GetIdentityGroup() Identity
}

IdentityGroupProvider can be implemented by tightly connected types. Current use case is Resource transformation via Hugo Pipes.

type IdentityProvider

type IdentityProvider interface {
	GetIdentity() Identity
}

IdentityProvider can be implemented by types that isn't itself and Identity, usually because they're not comparable/hashable.

type IncrementByOne

type IncrementByOne struct {
	// contains filtered or unexported fields
}

IncrementByOne implements Incrementer adding 1 every time Incr is called.

func (*IncrementByOne) Incr

func (c *IncrementByOne) Incr() int

type Incrementer

type Incrementer interface {
	Incr() int
}

Incrementer increments and returns the value. Typically used for IDs.

type IsProbablyDependencyProvider

type IsProbablyDependencyProvider interface {
	IsProbablyDependency(other Identity) bool
}

IsProbablyDependencyProvider is an optional interface for Identity.

type IsProbablyDependentProvider

type IsProbablyDependentProvider interface {
	IsProbablyDependent(other Identity) bool
}

IsProbablyDependentProvider is an optional interface for Identity.

type Manager

type Manager interface {
	Identity
	AddIdentity(ids ...Identity)
	AddIdentityForEach(ids ...ForEeachIdentityProvider)
	GetIdentity() Identity
	Reset()
	// contains filtered or unexported methods
}

Manager is an Identity that also manages identities, typically dependencies.

func GetDependencyManager

func GetDependencyManager(v any) Manager

GetDependencyManager returns the DependencyManager from v or nil if none found.

func NewManager

func NewManager(name string, opts ...ManagerOption) Manager

NewIdentityManager creates a new Manager.

type ManagerIdentity

type ManagerIdentity struct {
	Identity
	Manager
}

ManagerIdentity wraps a pair of Identity and Manager.

func (ManagerIdentity) String

func (p ManagerIdentity) String() string

type ManagerOption

type ManagerOption func(m *identityManager)

type Provider

type Provider interface {
	GetIdentity() Identity
}

Provider can be implemented by types that isn't itself and Identity, usually because they're not comparable/hashable.

type StringIdentity

type StringIdentity string

StringIdentity is an Identity that wraps a string.

func CleanStringIdentity

func CleanStringIdentity(s string) StringIdentity

CleanStringIdentity cleans s to be suitable as an identifier and wraps it in a StringIdentity.

func (StringIdentity) IdentifierBase

func (s StringIdentity) IdentifierBase() string

Jump to

Keyboard shortcuts

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