common

package
v0.0.0-...-8808a61 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyOperationHSet    string = "hset"
	KeyOperationSet     string = "set"
	KeyOperationDel     string = "del"
	KeyOperationExpire  string = "expire"
	KeyOperationExpired string = "expired"
)

Variables

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

Functions

func AuthInterceptor

func AuthInterceptor(token string) grpc.UnaryClientInterceptor

func ConcatTags

func ConcatTags(metric string, tags *map[string]string) string

func CopyStruct

func CopyStruct(src, dst interface{})

Attempts to copy field values of the same name from the src to the dst struct.

func ExtractObjectFile

func ExtractObjectFile(ctx context.Context, objectId string, workspaceName string) error

func GenerateObjectId

func GenerateObjectId() (string, error)

This simulates Mongo's object ID function which utilizes a 4-byte encoded timestamp value in the beginning of the id Used to even further reduce any chance of collision across distributed containers

func GetAWSConfig

func GetAWSConfig(accessKey string, secretKey string, region string, endpoint string) (aws.Config, error)

func GetConfigParser

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

func ToSlice

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

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

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] type for managing configuration of type 'T'. It initializes the ConfigManager with the specified 'T' type, loads a default configuration, and optionally loads a user configuration if the 'CONFIG_PATH' environment variable is provided. 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
}

func NewContainerOverlay

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

func (*ContainerOverlay) AddEmptyLayer

func (co *ContainerOverlay) AddEmptyLayer() error

func (*ContainerOverlay) AddLayer

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

func (*ContainerOverlay) Cleanup

func (co *ContainerOverlay) Cleanup() error

func (*ContainerOverlay) Setup

func (co *ContainerOverlay) Setup() error

func (*ContainerOverlay) TopLayerPath

func (co *ContainerOverlay) TopLayerPath() string

type ContainerOverlayLayer

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

type Event

type Event struct {
	Type          EventType      `json:"type"`
	Args          map[string]any `json:"args"`
	LockAndDelete bool           `json:"lock_and_delete"`
	Retries       uint           `json:"retries"`
}

type EventBus

type EventBus struct {
	EventCallbacks map[string]func(*Event) bool
	Subscribers    []EventBusSubscriber
	// contains filtered or unexported fields
}

func NewEventBus

func NewEventBus(rdb *RedisClient, subscribers ...EventBusSubscriber) *EventBus

Create a new event bus

func (*EventBus) Claim

func (eb *EventBus) Claim(eventId string) (*Event, *RedisLock, bool)

Claim an event for processing

func (*EventBus) Delete

func (eb *EventBus) Delete(eventId string) error

Remove an event by ID

func (*EventBus) ReceiveEvents

func (eb *EventBus) ReceiveEvents(ctx context.Context)

Receive all subscribed events (blocking)

func (*EventBus) Send

func (eb *EventBus) Send(event *Event) (string, error)

Send an event over the bus

type EventBusSubscriber

type EventBusSubscriber struct {
	Type     EventType
	Callback func(*Event) bool
}

type EventType

type EventType string
const (
	EventTypeStopContainer  EventType = "STOP_CONTAINER"
	EventTypeReloadInstance EventType = "RELOAD_INSTANCE"
)

type ImageRegistry

type ImageRegistry struct {
	ImageFileExtension string
	// contains filtered or unexported fields
}

func NewImageRegistry

func NewImageRegistry(config types.ImageServiceConfig) (*ImageRegistry, error)

func (*ImageRegistry) Exists

func (r *ImageRegistry) Exists(ctx context.Context, imageId string) bool

func (*ImageRegistry) Pull

func (r *ImageRegistry) Pull(ctx context.Context, localPath string, imageId string) error

func (*ImageRegistry) Push

func (r *ImageRegistry) Push(ctx context.Context, localPath string, imageId string) error

func (*ImageRegistry) Size

func (r *ImageRegistry) Size(ctx context.Context, imageId string) (int64, error)

type KeyEvent

type KeyEvent struct {
	Key       string
	Operation string
}

type KeyEventManager

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

func NewKeyEventManager

func NewKeyEventManager(rdb *RedisClient) (*KeyEventManager, error)

func (*KeyEventManager) ListenForPattern

func (kem *KeyEventManager) ListenForPattern(ctx context.Context, patternPrefix string, keyEventChan chan KeyEvent) error

type LocalObjectStore

type LocalObjectStore struct {
	Path string
}

func NewLocalObjectStore

func NewLocalObjectStore() (*LocalObjectStore, error)

func (*LocalObjectStore) Exists

func (s *LocalObjectStore) Exists(ctx context.Context, key string) bool

func (*LocalObjectStore) Get

func (s *LocalObjectStore) Get(ctx context.Context, key string, localPath string) error

func (*LocalObjectStore) Put

func (s *LocalObjectStore) Put(ctx context.Context, localPath string, key string) error

func (*LocalObjectStore) Size

func (s *LocalObjectStore) Size(ctx context.Context, key string) (int64, error)

type LogBuffer

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

func NewLogBuffer

func NewLogBuffer() *LogBuffer

func (*LogBuffer) Close

func (lb *LogBuffer) Close()

func (*LogBuffer) Read

func (lb *LogBuffer) Read(p []byte) (n int, err error)

func (*LogBuffer) Write

func (lb *LogBuffer) Write(buf []byte)

type ObjectStore

type ObjectStore interface {
	Put(ctx context.Context, localPath string, key string) error
	Get(ctx context.Context, key string, localPath string) error
	Exists(ctx context.Context, key string) bool
	Size(ctx context.Context, key string) (int64, error)
}

type OutputMsg

type OutputMsg struct {
	Msg     string
	Done    bool
	Success bool
	ImageId string
}

type OutputWriter

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

func NewOutputWriter

func NewOutputWriter(outputCallback func(string)) *OutputWriter

func (*OutputWriter) Write

func (w *OutputWriter) Write(p []byte) (n int, err error)

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)

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

func (*RedisClient) LRange

func (r *RedisClient) LRange(ctx context.Context, key string, start, stop int64) ([]string, error)

func (*RedisClient) PSubscribe

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

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
}

type RunCClient

type RunCClient struct {
	ServiceUrl   string
	ServiceToken string
	// contains filtered or unexported fields
}

func NewRunCClient

func NewRunCClient(serviceUrl, serviceToken string, existingConn net.Conn) (*RunCClient, error)

func (*RunCClient) Archive

func (c *RunCClient) Archive(ctx context.Context, containerId, imageId string, outputChan chan OutputMsg) error

func (*RunCClient) Close

func (c *RunCClient) Close() error

func (*RunCClient) Exec

func (c *RunCClient) Exec(containerId, cmd string) (*pb.RunCExecResponse, error)

func (*RunCClient) Kill

func (c *RunCClient) Kill(containerId string) (*pb.RunCKillResponse, error)

func (*RunCClient) Status

func (c *RunCClient) Status(containerId string) (*pb.RunCStatusResponse, error)

func (*RunCClient) StreamLogs

func (c *RunCClient) StreamLogs(ctx context.Context, containerId string, outputChan chan OutputMsg) error

type S3Store

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

func NewS3Store

func NewS3Store(config types.S3ImageRegistryConfig) (*S3Store, error)

func (*S3Store) Exists

func (s *S3Store) Exists(ctx context.Context, key string) bool

Exists returns true if the object exists

func (*S3Store) Get

func (s *S3Store) Get(ctx context.Context, key string, localPath string) error

func (*S3Store) Put

func (s *S3Store) Put(ctx context.Context, localPath string, key string) error

func (*S3Store) Size

func (s *S3Store) Size(ctx context.Context, key string) (int64, error)

Size returns the size of the object in bytes

type SafeMap

type SafeMap[V any] struct {
	// contains filtered or unexported fields
}

func NewSafeMap

func NewSafeMap[V any]() *SafeMap[V]

NewSafeMap initializes a new SafeMap with the specified value type.

func (*SafeMap[V]) Delete

func (m *SafeMap[V]) Delete(key string)

func (*SafeMap[V]) Get

func (m *SafeMap[V]) Get(key string) (V, bool)

func (*SafeMap[V]) Len

func (m *SafeMap[V]) Len() int

func (*SafeMap[V]) Range

func (m *SafeMap[V]) Range(f func(key string, value V) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*SafeMap[V]) Set

func (m *SafeMap[V]) Set(key string, value V)

type StatsdSender

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

func GetStatSender

func GetStatSender() *StatsdSender

func InitStatsdSender

func InitStatsdSender(uri string) *StatsdSender

func (*StatsdSender) StatCount

func (s *StatsdSender) StatCount(metric string, value int)

func (*StatsdSender) StatCountTags

func (s *StatsdSender) StatCountTags(metric string, value int, tags map[string]string)

func (*StatsdSender) StatGauge

func (s *StatsdSender) StatGauge(metric string, value int)

func (*StatsdSender) StatGaugeTags

func (s *StatsdSender) StatGaugeTags(metric string, value int, tags map[string]string)

func (*StatsdSender) StatTime

func (s *StatsdSender) StatTime(metric string, value time.Duration)

func (*StatsdSender) StatTimeTags

func (s *StatsdSender) StatTimeTags(metric string, value time.Duration, tags map[string]string)

Jump to

Keyboard shortcuts

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