base

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: BSD-2-Clause Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheNotFound = stderrors.New("key not found")
	ErrCacheExpired  = stderrors.New("key expired")

	// Deprecated: Use ErrCacheNotFound instead.
	CacheNotFoundError = ErrCacheNotFound //nolint:errname
	// Deprecated: Use ErrCacheExpired instead.
	CacheExpiredError = ErrCacheExpired //nolint:errname
)

Functions

func CreateInitialDelayTrigger

func CreateInitialDelayTrigger(
	ctx context.Context,
	initalDelay libtime.Duration,
) run.Trigger

func NewResultMessageHandler

func NewResultMessageHandler(
	resultHandler ResultHandler,
	logSamplerFactory log.SamplerFactory,
) kafka.MessageHandler

func NewResultMessageHandlerTx

func NewResultMessageHandlerTx(
	resultHandler ResultHandlerTx,
	logSamplerFactory log.SamplerFactory,
) kafka.MessageHandlerTx

func RequestIDChannel

func RequestIDChannel(ctx context.Context) <-chan RequestID

RequestIDChannel provides a channel of RequestIDs for high performance operations.

Types

type Branch

type Branch string

func (Branch) String

func (b Branch) String() string

type Cache

type Cache[Key CacheKey, Value any] interface {
	CacheAdder[Key, Value]
	CacheGetter[Key, Value]
	CacheCleaner
}

func NewCache

func NewCache[Key CacheKey, Value any](
	getter libtime.CurrentDateTimeGetter,
	expireDuration libtime.Duration,
) Cache[Key, Value]

type CacheAdder

type CacheAdder[Key CacheKey, Value any] interface {
	Add(ctx context.Context, key Key, value Value) error
}

type CacheCleaner

type CacheCleaner interface {
	Clean(ctx context.Context) error
}

type CacheGetter

type CacheGetter[Key CacheKey, Value any] interface {
	Get(ctx context.Context, key Key) (*Value, error)
}

type CacheKey

type CacheKey interface {
	comparable
}

type CacheValue

type CacheValue[Value any] struct {
	Value    Value
	DateTime libtime.DateTime
}

type Command

type Command struct {
	RequestID   RequestID        `json:"requestID"`
	RequestTime time.Time        `json:"requestTime"`
	Initiator   iam.Initiator    `json:"initiator"`
	Operation   CommandOperation `json:"operation"`
	ID          EventID          `json:"id"`
	Data        Event            `json:"data"`
	Header      CommandHeader    `json:"header"`
}

func (Command) Ptr

func (c Command) Ptr() *Command

func (Command) Validate

func (c Command) Validate(ctx context.Context) error

type CommandCreator

type CommandCreator interface {
	NewCommand(operation CommandOperation, initiator iam.Initiator, id EventID, data Event) Command
	NewCommandWithHeader(
		operation CommandOperation,
		initiator iam.Initiator,
		id EventID,
		data Event,
		header CommandHeader,
	) Command
	CreateCommand(initiator iam.Initiator, data Event) Command
	UpdateCommand(initiator iam.Initiator, id EventID, data Event) Command
	PatchCommand(initiator iam.Initiator, id EventID, data Event) Command
	DeleteCommand(initiator iam.Initiator, id EventID) Command
}

func NewCommandCreator

func NewCommandCreator(requestIDChan <-chan RequestID) CommandCreator

type CommandHeader

type CommandHeader map[string]string

type CommandHeaders

type CommandHeaders []CommandHeader

func (CommandHeaders) Merge

func (c CommandHeaders) Merge() CommandHeader

type CommandOperation

type CommandOperation string
const (
	CreateOperation CommandOperation = "create"
	DeleteOperation CommandOperation = "delete"
	UpdateOperation CommandOperation = "update"
	PatchOperation  CommandOperation = "patch"
)

func CommandOperationFromMethod

func CommandOperationFromMethod(method string) CommandOperation

func (CommandOperation) Method

func (c CommandOperation) Method() string

func (CommandOperation) String

func (c CommandOperation) String() string

func (CommandOperation) Validate

func (c CommandOperation) Validate(ctx context.Context) error

type Event

type Event map[FieldName]interface{}

Event contains all data of an event

func ParseEvent

func ParseEvent(ctx context.Context, value interface{}) (Event, error)

func (Event) Get

func (e Event) Get(name FieldName) (interface{}, bool)

func (Event) MarshalInto

func (e Event) MarshalInto(ctx context.Context, into interface{}) error

func (Event) Merge

func (e Event) Merge(event Event) Event

Merge this and the given event, given overwrite this

func (Event) Ptr

func (e Event) Ptr() *Event

func (Event) Set

func (e Event) Set(name FieldName, value interface{}) Event

func (Event) Validate

func (e Event) Validate(ctx context.Context) error

type EventID

type EventID string

func ParseEventID

func ParseEventID(ctx context.Context, value interface{}) (*EventID, error)

func (EventID) Bytes

func (e EventID) Bytes() []byte

func (EventID) Equal

func (e EventID) Equal(eventID EventID) bool

func (EventID) Ptr

func (e EventID) Ptr() *EventID

func (EventID) String

func (e EventID) String() string

type EventIDs

type EventIDs []EventID

func EventIDsFromStrings

func EventIDsFromStrings(ids []string) EventIDs

func ParseEventIDs

func ParseEventIDs(ctx context.Context, value interface{}) (EventIDs, error)

func (EventIDs) Add

func (e EventIDs) Add(eventID EventID) EventIDs

Add eventId to List if not already in

func (EventIDs) Contains

func (e EventIDs) Contains(eventID EventID) bool

Contains eventId to List if in

func (EventIDs) Len

func (e EventIDs) Len() int

func (EventIDs) Less

func (e EventIDs) Less(i, j int) bool

func (EventIDs) Remove

func (e EventIDs) Remove(eventID EventID) EventIDs

Remove eventId to List if in

func (EventIDs) Strings

func (e EventIDs) Strings() []string

func (EventIDs) Swap

func (e EventIDs) Swap(i, j int)

type FieldName

type FieldName string

func (FieldName) String

func (f FieldName) String() string

type FieldNames

type FieldNames []FieldName

func ParseFieldNames

func ParseFieldNames(values []string) FieldNames

func ParseFieldNamesFromString

func ParseFieldNamesFromString(value string) FieldNames

func (FieldNames) Len

func (f FieldNames) Len() int

func (FieldNames) Less

func (f FieldNames) Less(i, j int) bool

func (FieldNames) Strings

func (f FieldNames) Strings() []string

func (FieldNames) Swap

func (f FieldNames) Swap(i, j int)

type Identifier

type Identifier string

Identifier a Signal, ExpectedBase or ActualBase

func (Identifier) Bytes

func (i Identifier) Bytes() []byte

func (Identifier) Equal

func (i Identifier) Equal(identifier ObjectIdentifier) bool

func (Identifier) String

func (i Identifier) String() string

func (Identifier) Validate

func (i Identifier) Validate(ctx context.Context) error

type IdentifierGenerator

type IdentifierGenerator[Identifier ~string | ~[]byte] interface {
	NewIdentifier() Identifier
}

func NewIdentifierGeneratorCounter

func NewIdentifierGeneratorCounter[Identifier ~string | ~[]byte]() IdentifierGenerator[Identifier]

func NewIdentifierGeneratorUUID

func NewIdentifierGeneratorUUID[Identifier ~string | ~[]byte]() IdentifierGenerator[Identifier]

type IdentifierGeneratorFunc

type IdentifierGeneratorFunc[Identifier ~string | ~[]byte] func() Identifier

func (IdentifierGeneratorFunc[Identifier]) NewIdentifier

func (t IdentifierGeneratorFunc[Identifier]) NewIdentifier() Identifier

type Identifiers

type Identifiers []Identifier

func ParseIdentifiers

func ParseIdentifiers(values []string) Identifiers

func (Identifiers) Contains

func (t Identifiers) Contains(identifier Identifier) bool

func (Identifiers) Interfaces

func (t Identifiers) Interfaces() []interface{}

type Object

type Object[I ObjectIdentifier] struct {
	Identifier I `json:"identifier"`

	// Create time of the expectedTrade
	Created libtime.DateTime `json:"created"`

	// Modified of the actual trade
	Modified libtime.DateTime `json:"modified"`
}

func (Object[I]) Clone

func (b Object[I]) Clone() Object[I]

func (Object[I]) Equal

func (b Object[I]) Equal(base Object[I]) bool

func (Object[I]) Validate

func (b Object[I]) Validate(ctx context.Context) error

type ObjectIdentifier

type ObjectIdentifier interface {
	validation.HasValidation
	Equal(identifier ObjectIdentifier) bool
}

type Provider

type Provider[T any] interface {
	Get(ctx context.Context) (T, error)
}

type ProviderFunc

type ProviderFunc[T any] func(ctx context.Context) (T, error)

func (ProviderFunc[T]) Get

func (p ProviderFunc[T]) Get(ctx context.Context) (T, error)

type RequestID

type RequestID string

RequestID identify each request/command and the corresponding result.

func NewRequestID

func NewRequestID() RequestID

NewRequestID returns a new RequestID. RequestIDChannel pre generates RequestIDs for better performance.

func (RequestID) Bytes

func (r RequestID) Bytes() []byte

func (RequestID) String

func (r RequestID) String() string

func (RequestID) Validate

func (r RequestID) Validate(ctx context.Context) error

type Result

type Result struct {
	RequestID   RequestID        `json:"requestID"`
	RequestTime time.Time        `json:"requestTime"`
	Initiator   iam.Initiator    `json:"initiator"`
	Operation   CommandOperation `json:"operation"`
	ID          EventID          `json:"id"`
	Data        Event            `json:"data"`
	Header      CommandHeader    `json:"header"`
	Success     bool             `json:"success"`
	Message     string           `json:"message"`
}

func (Result) Validate

func (r Result) Validate(ctx context.Context) error

type ResultHandler

type ResultHandler interface {
	HandleResult(ctx context.Context, result Result) error
}

type ResultHandlerFunc

type ResultHandlerFunc func(ctx context.Context, result Result) error

func (ResultHandlerFunc) HandleResult

func (r ResultHandlerFunc) HandleResult(ctx context.Context, result Result) error

type ResultHandlerList

type ResultHandlerList []ResultHandler

func (ResultHandlerList) HandleResult

func (c ResultHandlerList) HandleResult(ctx context.Context, result Result) error

type ResultHandlerTx

type ResultHandlerTx interface {
	HandleResult(ctx context.Context, tx libkv.Tx, result Result) error
}

func NewResultHandlerTxLog

func NewResultHandlerTxLog(
	logSamplerFactory log.SamplerFactory,
) ResultHandlerTx

type ResultHandlerTxFunc

type ResultHandlerTxFunc func(ctx context.Context, tx libkv.Tx, result Result) error

func (ResultHandlerTxFunc) HandleResult

func (r ResultHandlerTxFunc) HandleResult(ctx context.Context, tx libkv.Tx, result Result) error

type ResultHandlerTxList

type ResultHandlerTxList []ResultHandlerTx

func (ResultHandlerTxList) HandleResult

func (c ResultHandlerTxList) HandleResult(ctx context.Context, tx libkv.Tx, result Result) error

type ResultHandlerTxOperation

type ResultHandlerTxOperation map[CommandOperation]ResultHandlerTx

ResultHandlerTxOperation allow define result handler per option

func (ResultHandlerTxOperation) HandleResult

func (r ResultHandlerTxOperation) HandleResult(
	ctx context.Context,
	tx libkv.Tx,
	result Result,
) error

Jump to

Keyboard shortcuts

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