config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerAddr = "0.0.0.0"
	DefaultServerPort = 8080

	DefaultDBMaxOpen     = 20
	DefaultDBMaxIdle     = 10
	DefaultDBMaxLifetime = 60 * time.Minute
	DefaultDBMaxIdletime = 15 * time.Minute
)

Variables

View Source
var (
	DefaultWorkerConcurrency = runtime.NumCPU()
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Bot      SlackBotConfig
	Database DatabaseConfig
	Server   ServerConfig
	Worker   WorkerConfig
	Tracing  TracingConfig
	Dev      bool
}

Config stores the configuration for the application

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a file and environment variables

func (*Config) GetAddr

func (c *Config) GetAddr() string

GetAddr returns the addr of the server

func (Config) Validate

func (c Config) Validate() error

Validate verifies the configuration

type DBConnectionsConfig

type DBConnectionsConfig struct {
	// MaxOpen is the maximum number of open connections.
	//
	// Optional
	MaxOpen int `mapstructure:"max_open"`

	// MaxIdle is the maximum number of idle connections.
	//
	// Optional
	MaxIdle int `mapstructure:"max_idle"`

	// MaxLifeTime is the maximum lifetime of connections.
	//
	// Optional
	MaxLifetime time.Duration `mapstructure:"max_lifetime"`

	// MaxIdleTime is the maximum amount of time a connection can be idle.
	//
	// Optional
	MaxIdletime time.Duration `mapstructure:"max_idletime"`
}

DBConnectionsConfig stores the configuration for the database connection pool

See also: https://go.dev/doc/database/manage-connections

type DBEncryptionConfig

type DBEncryptionConfig struct {
	// Key is the current data encryption key (DEK) used to encrypt and decrypt data.
	// This must be a 32-byte hex-encoded key.
	//
	// Required
	Key string

	// PreviousKey is the key used to decrypt old data. This should
	// only be set if the data encryption key is being rotated.
	// If set, this must be a 32-byte hex-encoded key.
	//
	// Optional
	PreviousKey string `mapstructure:"previous_key"`
}

DBEncryptionConfig stores the configuration for encrypting data in the database.

func (*DBEncryptionConfig) GetDEK

func (d *DBEncryptionConfig) GetDEK() ([]byte, error)

GetDEK returns the hex-decoded DEK

func (*DBEncryptionConfig) GetPreviousDEK

func (d *DBEncryptionConfig) GetPreviousDEK() ([]byte, error)

GetDEK returns the hex-decoded previous DEK

type DatabaseConfig

type DatabaseConfig struct {
	// URL is the PostgreSQL connection URL
	//
	// Required
	URL string

	// Connections is the database connections configuration
	//
	// Optional
	Connections DBConnectionsConfig

	// Encryption is the database encryption configuration
	//
	// Required
	Encryption DBEncryptionConfig
}

DatabaseConfig stores the configuration for using the database

type HoneycombTracing

type HoneycombTracing struct {
	// Team is the Honeycomb API key to use
	//
	// Required
	Team string `mapstructure:"team"`

	// Dataset is the destination dataset to send traces to
	//
	// Required
	Dataset string `mapstructure:"dataset"`
}

HoneycombTracing contains configuration for the Honeycomb exporter

type JaegerTracing

type JaegerTracing struct {
	// Endpoint is the URL of the Jaeger collector.
	// This is typically "http://localhost:4318/v1/traces"
	//
	// Required
	Endpoint string `mapstructure:"endpoint"`
}

JaegerTracing contains configuration for the Jaeger exporter

type ServerConfig

type ServerConfig struct {
	// Address is the address that the server binds on.
	//
	// Optional, defaults to 0.0.0.0
	Address string

	// Port is the TCP port that the server binds on.
	//
	// Optional, defaults to 8080
	Port int

	// ClientID is the Slack OpenID Connect (OIDC) client ID.
	//
	// Required
	ClientID string `mapstructure:"client_id"`

	// Client Secret is Slack OpenID Connect (OIDC) client secret.
	//
	// Required
	ClientSecret string `mapstructure:"client_secret"`

	// RedirectURL is the Slack OpenID Connect (OIDC) redirect URL.
	//
	// Required
	RedirectURL string `mapstructure:"redirect_url"`

	// SecretKey is the 32-byte hex-encoded secret key used to authenticate cookies.
	//
	// Required
	SecretKey string `mapstructure:"secret_key"`

	// SigningSecret is the secret used to authenticate requests received from Slack.
	//
	// Required
	SigningSecret string `mapstructure:"signing_secret"`
}

ServerConfig stores the configuration for the bot server

func (*ServerConfig) GetSecretKey

func (s *ServerConfig) GetSecretKey() ([]byte, error)

GetSecretKey returns the hex-decoded Secret Key

type SlackBotConfig

type SlackBotConfig struct {
	// AuthToken is the Slack OAuth2 bot token
	//
	// Required
	AuthToken string `mapstructure:"auth_token"`
}

SlackBotConfig stores the configuration for the Slack bot

type TracingConfig

type TracingConfig struct {
	// Enabled turns on OpenTelemetry tracing.
	//
	// Optional
	Enabled bool `mapstructure:"enabled"`

	// Exporter sets the tracing exporter to use.
	// The only options currently supported are: jaeger or honeycomb.
	//
	// Optional
	Exporter TracingExporter `mapstructure:"exporter"`

	// Jaeger stores the configuration for the Jaeger exporter
	//
	// Optional, required if Exporter=jaeger
	Jaeger JaegerTracing `mapstructure:"jaeger"`

	// Honeycomb stores the configuration for the Honeycomb exporter
	//
	// Optional, required if Exporter=honeycomb
	Honeycomb HoneycombTracing `mapstructure:"honeycomb"`
}

TracingConfig stores the configuration for OpenTelemetry tracing. Only one exporter can be configured at a time.

type TracingExporter

type TracingExporter string
const (
	TracingExporterJaeger    TracingExporter = "jaeger"
	TracingExporterHoneycomb TracingExporter = "honeycomb"
)

type WorkerConfig

type WorkerConfig struct {
	// Concurrency is the number of concurrent workers to run
	//
	// Optional, defaults to the number of CPU cores
	Concurrency int
}

WorkerConfig stores the configuration for the task queue workers

Jump to

Keyboard shortcuts

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