kg

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AudiencePeer = "PEER"
	AudienceAny  = "ANY"
)

Audience reserved words.

Variables

This section is empty.

Functions

func NormalizeAudience

func NormalizeAudience(name string) string

NormalizeAudience normalizes audience identity for the audience segment; panics on empty or reserved words.

func NormalizeCreator

func NormalizeCreator(name string) string

NormalizeCreator normalizes creator identity for the creator segment; panics on empty or reserved words.

func NormalizeSegment

func NormalizeSegment(name string) string

NormalizeSegment normalises a key segment: TrimSpace, ToUpper, '-' to '_'.

Types

type KeyCode

type KeyCode interface {
	~int | ~int32 | ~int64 | ~uint | ~uint32 | ~uint64 | ~string
}

KeyCode constrains the biz-key segment to common scalar types.

type KeyGen

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

KeyGen generates structured cache keys using a four-segment convention. It must be initialized exactly once via KeyGen.Init before any key generation method is called.

func (*KeyGen) Creator

func (g *KeyGen) Creator() string

Creator returns the normalized creator identity.

func (*KeyGen) GlobalKey

func (g *KeyGen) GlobalKey(domain string, k any) string

GlobalKey returns a cross-service key: {creator}:ANY:{domain}:{biz}.

func (*KeyGen) GlobalKeyFrom

func (g *KeyGen) GlobalKeyFrom(creatorIdentity, domain string, k any) string

GlobalKeyFrom reads a cross-service key created by another creator identity.

func (*KeyGen) Init

func (g *KeyGen) Init(creator string, opts ...Option)

Init locks the creator identity and generates a per-process ULID instance ID. Subsequent calls are no-ops (the first result is retained).

func (*KeyGen) InstanceID

func (g *KeyGen) InstanceID() string

InstanceID returns the per-process instance audience (ULID).

func (*KeyGen) Key

func (g *KeyGen) Key(domain string, k any) string

Key returns a process-exclusive key: {creator}:{ulid}:{domain}:{biz}.

func (*KeyGen) Prefix

func (g *KeyGen) Prefix() string

Prefix returns the optional namespace prefix.

func (*KeyGen) ShareFrom

func (g *KeyGen) ShareFrom(creatorIdentity, audienceIdentity, domain string, k any) string

ShareFrom reads a key shared by creator identity to audience identity.

func (*KeyGen) ShareTo

func (g *KeyGen) ShareTo(audienceIdentity, domain string, k any) string

ShareTo returns a key shared with a target identity: {creator}:{audience}:{domain}:{biz}.

func (*KeyGen) SharedKey

func (g *KeyGen) SharedKey(domain string, k any) string

SharedKey returns a peer-shared key: {creator}:PEER:{domain}:{biz}.

func (*KeyGen) SharedKeyFrom

func (g *KeyGen) SharedKeyFrom(creatorIdentity, domain string, k any) string

SharedKeyFrom reads a PEER key created by another creator identity.

type Option

type Option func(*KeyGen)

Option configures a KeyGen at Init time.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix prepends a static namespace segment before the four-segment key, producing {prefix}:{creator}:{audience}:{domain}:{biz}.

Jump to

Keyboard shortcuts

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