common

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilMessage       = errors.New("redis: nil message")
	ErrChannelClosed    = errors.New("redis: channel closed")
	ErrConnectionIssue  = errors.New("redis: connection issue")
	ErrUnknownRedisMode = errors.New("redis: unknown mode")
)
View Source
var Keys = &redisKeys{}

Functions

func CopyStruct

func CopyStruct(src, dst any) error

func GenerateID

func GenerateID(prefix string) string

GenerateID generates a unique ID with the given prefix. Format: prefix-timestamp-random

func GenerateRandomID

func GenerateRandomID(length int) string

GenerateRandomID generates a random ID of the specified length.

func GenerateSessionID

func GenerateSessionID() string

GenerateSessionID generates a unique session ID.

func GenerateWorkerID

func GenerateWorkerID() string

GenerateWorkerID generates a unique worker ID.

func GetConfigParser

func GetConfigParser(format ConfigFormat) (koanf.Parser, error)

func ToSlice

func ToSlice(v interface{}) []interface{}

ToSlice flattens a struct using its field tags so it can be used by HSet. Struct fields must have the redis tag on them otherwise they will be ignored.

func ToStruct

func ToStruct(m map[string]string, out interface{}) error

ToStruct copies the result of HGetAll to a provided struct. If a field cannot be parsed, we use Go's default value. Struct fields must have the redis tag on them otherwise they will be ignored.

func WithClientName

func WithClientName(name string) func(*redis.UniversalOptions)

Types

type ConfigFormat

type ConfigFormat string
var (
	JSONConfigFormat ConfigFormat = ".json"
	YAMLConfigFormat ConfigFormat = ".yaml"
	YMLConfigFormat  ConfigFormat = ".yml"
)

type ConfigLoaderFunc

type ConfigLoaderFunc func(k *koanf.Koanf) error

ConfigLoaderFunc is a function type used to load configuration into a Koanf instance. It takes a Koanf pointer 'k' as a parameter and returns an error if the loading process encounters any issues.

type ConfigManager

type ConfigManager[T any] struct {
	// contains filtered or unexported fields
}

ConfigManager is a generic configuration manager that allows handling and manipulation of configuration data for various types. It includes a Koanf instance ('kf') for managing configuration settings.

func NewConfigManager

func NewConfigManager[T any]() (*ConfigManager[T], error)

NewConfigManager creates a new instance of the ConfigManager[T]. It initializes a Koanf instance and loads the default configuration. It then loads the configuration from the /etc/airstore.d/ directory and the user-specified configuration file from CONFIG_PATH. If the CONFIG_JSON environment variable is set, it loads the configuration from the JSON string. If debug mode is enabled, it prints the current configuration.

func (*ConfigManager[T]) GetConfig

func (cm *ConfigManager[T]) GetConfig() T

GetConfig retrieves the current configuration of type 'T' from the ConfigManager. It unmarshals the configuration data and returns it. If any errors occur during unmarshaling, it logs a fatal error and exits the application.

func (*ConfigManager[T]) LoadConfig

func (cm *ConfigManager[T]) LoadConfig(format ConfigFormat, provider koanf.Provider) error

LoadConfig loads configuration data from a given provider in the specified format into the ConfigManager. It obtains a parser for the format, and then loads the configuration data. If any errors occur during the loading process, they are returned as an error.

func (*ConfigManager[T]) Print

func (cm *ConfigManager[T]) Print() string

Print returns a string representation of the current configuration state.

type ContainerOverlay

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

ContainerOverlay manages overlay filesystem layers for containers This creates a writable layer on top of a read-only base (e.g., CLIP FUSE mount)

func NewContainerOverlay

func NewContainerOverlay(sandboxID, rootPath, overlayPath string) *ContainerOverlay

NewContainerOverlay creates a new ContainerOverlay rootPath: the base rootfs (e.g., CLIP FUSE mount) overlayPath: where to store overlay layer data

func (*ContainerOverlay) AddEmptyLayer

func (co *ContainerOverlay) AddEmptyLayer() error

AddEmptyLayer adds an empty writable layer on top of the current stack

func (*ContainerOverlay) AddLayer

func (co *ContainerOverlay) AddLayer(upperDir string) error

AddLayer adds a pre-populated upper layer on top of the current stack

func (*ContainerOverlay) Cleanup

func (co *ContainerOverlay) Cleanup() error

Cleanup unmounts all layers and removes overlay directories

func (*ContainerOverlay) Setup

func (co *ContainerOverlay) Setup() error

Setup creates the initial overlay layer on top of the base rootfs

func (*ContainerOverlay) TopLayerPath

func (co *ContainerOverlay) TopLayerPath() string

TopLayerPath returns the merged path of the top overlay layer This is the path that should be used as the container rootfs

func (*ContainerOverlay) UpperLayerPath

func (co *ContainerOverlay) UpperLayerPath() string

UpperLayerPath returns the upper (writable) path of the top layer

type OverlayLayer

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

OverlayLayer represents a single overlay layer

type ParserFunc

type ParserFunc func() (koanf.Parser, error)

type RedisClient

type RedisClient struct {
	redis.UniversalClient
}

func NewRedisClient

func NewRedisClient(config types.RedisConfig, options ...func(*redis.UniversalOptions)) (*RedisClient, error)

func (*RedisClient) Keys

func (r *RedisClient) Keys(ctx context.Context, pattern string) ([]string, error)

Keys gets all keys using a pattern. Actually runs a scan since keys locks up the database.

func (*RedisClient) Publish

func (r *RedisClient) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd

func (*RedisClient) Scan

func (r *RedisClient) Scan(ctx context.Context, pattern string) ([]string, error)

func (*RedisClient) Subscribe

func (r *RedisClient) Subscribe(ctx context.Context, channels ...string) (<-chan *redis.Message, <-chan error)

func (*RedisClient) ToSlice

func (r *RedisClient) ToSlice(v interface{}) []interface{}

func (*RedisClient) ToStruct

func (r *RedisClient) ToStruct(m map[string]string, out interface{}) error

type RedisLock

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

func NewRedisLock

func NewRedisLock(client *RedisClient, opts ...RedisLockOption) *RedisLock

func (*RedisLock) Acquire

func (l *RedisLock) Acquire(ctx context.Context, key string, opts RedisLockOptions) error

func (*RedisLock) Release

func (l *RedisLock) Release(key string) error

type RedisLockOption

type RedisLockOption func(*RedisLock)

type RedisLockOptions

type RedisLockOptions struct {
	TtlS    int
	Retries int
}

Jump to

Keyboard shortcuts

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