config

package
v0.0.0-...-6af6dc0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparatorFunc

type ComparatorFunc func(a, b any) (int, error)

type Config

type Config struct {
	Redis     RedisConfig   `yaml:"redis" env-prefix:"WORKER_REDIS_"`
	DB        DBConfig      `yaml:"db" env-prefix:"WORKER_DB_"`
	PollDelay time.Duration `yaml:"pollDelay" env:"WORKER_POLL_DELAY" env-default:"2s"`
	Debug     bool          `yaml:"debug" env:"WORKER_DEBUG" env-default:"false"`
	BatchSize int           `yaml:"batchSize" env:"WORKER_BATCH_SIZE" env-default:"200"`
}

func Load

func Load(filename string) (*Config, bool, error)

type ConvertFunc

type ConvertFunc func(value string) (any, error)

type CursorConfig

type CursorConfig struct {
	Column  string `yaml:"column" env:"COLUMN" env-default:"id"`
	Type    string `yaml:"type" env:"TYPE" env-default:"int64"`
	Default string `yaml:"default" env:"DEFAULT" env-default:"-1"`
}

func (*CursorConfig) Info

func (c *CursorConfig) Info() (*CursorInfo, error)

type CursorInfo

type CursorInfo struct {
	Column      string
	Type        string
	Default     any
	CompareFunc ComparatorFunc
	ConvertFunc ConvertFunc
}

type DBConfig

type DBConfig struct {
	// ConnectionString is the full connection string to the database. If ConnectionString is provided, the other fields
	// are ignored.
	ConnectionString string `yaml:"connectionString" env:"CONNECTION_STRING"`
	DriverName       string `yaml:"driverName" env:"DRIVER_NAME" env-default:"postgres"`
	SelectQuery      string `` //nolint:lll
	/* 142-byte string literal not displayed */
	Cursor   CursorConfig `yaml:"cursor" env-prefix:"CURSOR_"`
	Host     string       `yaml:"host" env:"HOST" env-default:"localhost"`
	Port     int          `yaml:"port" env:"PORT" env-default:"5432"`
	User     string       `yaml:"user" env:"USER" env-default:"postgres"`
	Password string       `yaml:"password" env:"PASSWORD" env-default:"postgres"`
	DBName   string       `yaml:"dbName" env:"DBNAME" env-default:"postgres"`
	TLS      DBTLSConfig  `yaml:"tls" env-prefix:"TLS_"`
}

func (*DBConfig) BuildConnectionString

func (c *DBConfig) BuildConnectionString() (string, error)

type DBTLSConfig

type DBTLSConfig struct {
	Mode     string `yaml:"mode" env:"MODE" env-default:"disable"`
	RootCert string `yaml:"rootCert" env:"ROOTCERT"`
}

type KeyFunc

type KeyFunc func(row map[string]any) string

type RedisConfig

type RedisConfig struct {
	// URL is the connection string to the redis server. If URL is provided, the other fields are ignored.
	URL       string         `yaml:"url" env:"URL"`
	Host      string         `yaml:"host" env:"HOST" env-default:"localhost"`
	Port      int            `yaml:"port" env:"PORT" env-default:"6379"`
	User      string         `yaml:"user" env:"USER"`
	Password  string         `yaml:"password" env:"PASSWORD"`
	TLS       RedisTLSConfig `yaml:"tls" env-prefix:"TLS_"`
	Key       string         `yaml:"key" env:"KEY" env-default:"my-worker:${partition_key}:key"`
	Value     string         `yaml:"value" env:"VALUE" env-default:"${id}"`
	CursorKey string         `yaml:"cursorKey" env:"CURSOR_KEY" env-default:"my-worker:latest"`

	// TimestampKey is the key to store the timestamp that periodically gets written into redis to mark that the
	// worker is alive and processing rows (every worker poll).
	TimestampKey string `yaml:"timestampKey" env:"WRITER_TIMESTAMP_KEY"`
}

func (*RedisConfig) ClientOptions

func (c *RedisConfig) ClientOptions() (*redis.Options, error)

func (*RedisConfig) KeyFn

func (c *RedisConfig) KeyFn(logger *zap.Logger) (KeyFunc, error)

func (*RedisConfig) ValueFn

func (c *RedisConfig) ValueFn(logger *zap.Logger) (ValueFunc, error)

type RedisTLSConfig

type RedisTLSConfig struct {
	InsecureSkipVerify bool `yaml:"insecureSkipVerify" env:"INSECURE_SKIP_VERIFY" env-default:"false"`
}

type ValueFunc

type ValueFunc func(row map[string]any) any

Jump to

Keyboard shortcuts

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