cfg

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobConfig

type BlobConfig struct {
	ProjectURL string // Base project URL of the blob storage service
	APIKey     string // API key for authentication with the blob storage provider
	Bucket     string // Target bucket name for storing or retrieving objects
}

BlobConfig holds the configuration required to connect to a blob storage provider.

func LoadEnvBlobConfig

func LoadEnvBlobConfig(prefix ...string) (*BlobConfig, error)

LoadEnvBlobConfig loads BlobConfig from env vars with optional prefix.

func NewBlobConfig

func NewBlobConfig(url, apiKey, bucket string) *BlobConfig

func (*BlobConfig) WithAPIKey

func (cfg *BlobConfig) WithAPIKey(apiKey string) *BlobConfig

WithAPIKey sets the APIKey and returns the updated BlobConfig.

func (*BlobConfig) WithBucket

func (cfg *BlobConfig) WithBucket(bucket string) *BlobConfig

WithBucket sets the Bucket and returns the updated BlobConfig.

type DBConfig

type DBConfig struct {
	Driver      string        // Driver is used to set db engine (postgres, mysql and so on)
	DSN         string        // DSN is used to connect to the database
	PoolSize    uint8         // Maximum number of open connections in the pool
	MaxIdle     uint8         // Maximum number of idle connections in the pool
	MaxLifetime time.Duration // Maximum lifetime of a connection before it's recycled
}

DBConfig holds the configuration parameters for a database connection.

func LoadEnvDBConfig

func LoadEnvDBConfig(prefix ...string) (*DBConfig, error)

LoadEnvDBConfig loads the database configuration from environment variables. Required variables: DB_DSN, DB_POOL_SIZE, DB_MAX_IDLE, DB_MAX_LIFETIME.

func NewDBConfig

func NewDBConfig(driver, dsn string, size, maxIdle uint8, maxLT time.Duration) *DBConfig

func (*DBConfig) WithDSN

func (cfg *DBConfig) WithDSN(dsn string) *DBConfig

WithDSN sets the DSN string and returns the updated DBConfig.

func (*DBConfig) WithDriver added in v0.2.0

func (cfg *DBConfig) WithDriver(driver string) *DBConfig

WithDriver sets the Driver string and returns the updated DBConfig.

func (*DBConfig) WithIdle

func (cfg *DBConfig) WithIdle(idle uint8) *DBConfig

WithIdle sets the MaxIdle value and returns the updated DBConfig.

func (*DBConfig) WithMaxLifetime

func (cfg *DBConfig) WithMaxLifetime(maxTL time.Duration) *DBConfig

WithMaxLifetime sets the MaxLifetime value and returns the updated DBConfig.

func (*DBConfig) WithPoolSize

func (cfg *DBConfig) WithPoolSize(size uint8) *DBConfig

WithPoolSize sets the PoolSize and returns the updated DBConfig.

type EnvConfig added in v0.4.9

type EnvConfig struct {
	Mode   string // Application mode: development, staging, production
	Domain string // Public-facing domain, e.g., example.com
}

EnvConfig holds basic environment configuration like mode and domain.

func LoadEnvConfig added in v0.4.9

func LoadEnvConfig(prefix ...string) (*EnvConfig, error)

LoadEnvConfig loads EnvConfig from environment variables. Required vars: MODE, DOMAIN

func NewEnvConfig added in v0.4.9

func NewEnvConfig(mode, domain string) *EnvConfig

func (*EnvConfig) WithDomain added in v0.4.9

func (cfg *EnvConfig) WithDomain(domain string) *EnvConfig

WithDomain sets the domain and returns the updated EnvConfig.

func (*EnvConfig) WithMode added in v0.4.9

func (cfg *EnvConfig) WithMode(mode string) *EnvConfig

WithMode sets the mode and returns the updated EnvConfig.

type EnvGroupMap added in v1.0.0

type EnvGroupMap map[string]map[string]string

EnvGroupMap maps a prefix (e.g. "WEB", "EXE") to a set of environment variable suffixes and their values. For example, for "WEB_JWT_SECRET", the prefix is "WEB" and the suffix is "_JWT_SECRET".

func LoadEnvGroups added in v1.0.0

func LoadEnvGroups(suffixes []string, filenames ...string) (EnvGroupMap, error)

Extracts all env vars ending with the suffixes.

func (EnvGroupMap) GetGroup added in v1.0.0

func (e EnvGroupMap) GetGroup(prefix string) map[string]string

Retrieves env vars based on prefix.

type ExternalURLConfig added in v1.0.0

type ExternalURLConfig struct {
	URL string // External service URL
}

ExternalURLConfig holds configuration for an external URL.

func LoadEnvExternalURLConfig added in v1.0.0

func LoadEnvExternalURLConfig(prefix ...string) (*ExternalURLConfig, error)

LoadEnvExternalURLConfig loads ExternalURLConfig from environment variables. Optionally accepts a prefix to prepend to suffixes.

func NewExternalURLConfig added in v1.0.0

func NewExternalURLConfig(url string) *ExternalURLConfig

func (*ExternalURLConfig) WithURL added in v1.0.0

func (cfg *ExternalURLConfig) WithURL(url string) *ExternalURLConfig

WithURL sets the URL field and returns the updated config.

type JWTConfig

type JWTConfig struct {
	CookieName string        // Name of the cookie that stores the JWT
	Secret     string        // Secret key used to sign JWTs
	TokenTTL   time.Duration // Time-to-live duration of the token
}

JWTConfig holds the configuration related to JWT-based authentication.

func LoadEnvJWTConfig

func LoadEnvJWTConfig(prefix ...string) (*JWTConfig, error)

LoadEnvJWTConfig loads the JWT configuration from environment variables with optional prefix: JWT_COOKIE_NAME, JWT_SECRET, and JWT_TOKEN_TTL.

func NewJWTConfig

func NewJWTConfig(name, secret string, ttl time.Duration) *JWTConfig

func (*JWTConfig) WithCookieName

func (cfg *JWTConfig) WithCookieName(name string) *JWTConfig

WithCookieName sets the cookie name for the JWTConfig.

func (*JWTConfig) WithSecret

func (cfg *JWTConfig) WithSecret(secret string) *JWTConfig

WithSecret sets the secret key for signing JWTs in the JWTConfig.

func (*JWTConfig) WithTokenTTL

func (cfg *JWTConfig) WithTokenTTL(ttl time.Duration) *JWTConfig

WithTokenTTL sets the token time-to-live for the JWTConfig.

type KVConfig

type KVConfig struct {
	KVStoreURL string // URL of the key-value store
}

KVConfig holds configuration details for connecting to a key-value store.

func LoadEnvKVConfig

func LoadEnvKVConfig(prefix ...string) (*KVConfig, error)

LoadEnvKVConfig loads the key-value store configuration from environment variables, supporting an optional prefix.

func NewKVConfig

func NewKVConfig(kvStoreURL string) *KVConfig

func (*KVConfig) WithKVStoreURL

func (cfg *KVConfig) WithKVStoreURL(url string) *KVConfig

WithKVStoreURL sets a new key-value store URL and returns the updated KVConfig.

type MailerConfig

type MailerConfig struct {
	Host     string // SMTP server host
	Port     string // SMTP server port
	Username string // SMTP username for authentication
	Password string // SMTP password or token for authentication
	From     string // Default "From" email address
}

MailerConfig holds SMTP configuration for sending emails.

func LoadEnvMailerConfig

func LoadEnvMailerConfig(prefix ...string) (*MailerConfig, error)

LoadEnvMailerConfig loads MailerConfig values from environment variables, supporting an optional prefix.

func NewMailerConfig

func NewMailerConfig(host, port, username, password, from string) *MailerConfig

func (*MailerConfig) WithFrom

func (cfg *MailerConfig) WithFrom(from string) *MailerConfig

WithFrom sets the default "From" email address and returns the updated MailerConfig.

func (*MailerConfig) WithHost

func (cfg *MailerConfig) WithHost(host string) *MailerConfig

WithHost sets the SMTP host and returns the updated MailerConfig.

func (*MailerConfig) WithPassword

func (cfg *MailerConfig) WithPassword(password string) *MailerConfig

WithPassword sets the SMTP password and returns the updated MailerConfig.

func (*MailerConfig) WithPort

func (cfg *MailerConfig) WithPort(port string) *MailerConfig

WithPort sets the SMTP port and returns the updated MailerConfig.

func (*MailerConfig) WithUsername

func (cfg *MailerConfig) WithUsername(username string) *MailerConfig

WithUsername sets the SMTP username and returns the updated MailerConfig.

type MultiEnvBlobConfig added in v1.0.0

type MultiEnvBlobConfig = MultiEnvConfig[BlobConfig]

type MultiEnvConfig added in v1.0.0

type MultiEnvConfig[T any] map[string]*T

Represents maps of prefixes (e.g. "NEON", "UPSTASH", "WEB") to a set of EnvConfigs.

func LoadEnvBlobConfigs added in v1.0.0

func LoadEnvBlobConfigs() (MultiEnvConfig[BlobConfig], error)

LoadEnvBlobConfigs loads multiple BlobConfigs by scanning env vars with blob suffixes.

func LoadEnvConfigs added in v1.0.0

func LoadEnvConfigs() (MultiEnvConfig[EnvConfig], error)

LoadEnvConfigs scans env vars and builds env configs based on their prefix.

func LoadEnvDBConfigs added in v1.0.0

func LoadEnvDBConfigs() (MultiEnvConfig[DBConfig], error)

LoadEnvDBConfigs loads multiple DBConfig instances by scanning environment variables with the dbSuffixes keys and optional prefixes.

func LoadEnvExternalURLConfigs added in v1.0.0

func LoadEnvExternalURLConfigs() (MultiEnvConfig[ExternalURLConfig], error)

LoadEnvExternalURLConfigs loads multiple ExternalURLConfig from environment variables by scanning for all environment variable sets matching externalURLSuffixes.

func LoadEnvJWTConfigs added in v1.0.0

func LoadEnvJWTConfigs() (MultiEnvConfig[JWTConfig], error)

LoadEnvJWTConfigs scans env vars and builds JWT configs based on their prefix.

func LoadEnvKVConfigs added in v1.0.0

func LoadEnvKVConfigs() (MultiEnvConfig[KVConfig], error)

LoadEnvKVConfigs loads multiple KVConfig instances by scanning env vars with kvSuffixes.

func LoadEnvMailerConfigs added in v1.0.0

func LoadEnvMailerConfigs() (MultiEnvConfig[MailerConfig], error)

LoadEnvMailerConfigs loads multiple MailerConfigs by scanning env vars with mailer suffixes.

func LoadEnvOAuthConfigs added in v1.0.0

func LoadEnvOAuthConfigs() (MultiEnvConfig[OAuthConfig], error)

LoadEnvOAuthConfigs loads multiple OAuthConfigs by scanning env vars with oauth suffixes.

func LoadEnvPaymentConfigs added in v1.0.0

func LoadEnvPaymentConfigs() (MultiEnvConfig[PaymentConfig], error)

LoadEnvPaymentConfigs loads multiple PaymentConfigs by scanning env vars with payment suffixes.

func LoadEnvServerConfigs added in v1.0.0

func LoadEnvServerConfigs() (MultiEnvConfig[ServerConfig], error)

LoadEnvServerConfigs scans env vars and builds Server configs based on their prefix.

func LoadMultiEnvConfigs added in v1.0.0

func LoadMultiEnvConfigs[T any](
	suffixes []string,
	loader func(prefix ...string) (*T, error),
) (MultiEnvConfig[T], error)

Template func for loading envs with their prefixes.

type MultiEnvDBConfig added in v1.0.0

type MultiEnvDBConfig = MultiEnvConfig[DBConfig]

type MultiEnvEnvConfig added in v1.0.0

type MultiEnvEnvConfig = MultiEnvConfig[EnvConfig]

type MultiEnvExternalURLConfig added in v1.0.0

type MultiEnvExternalURLConfig = MultiEnvConfig[ExternalURLConfig]

type MultiEnvJWTConfig added in v1.0.0

type MultiEnvJWTConfig = MultiEnvConfig[JWTConfig]

type MultiEnvKVConfig added in v1.0.0

type MultiEnvKVConfig = MultiEnvConfig[KVConfig]

type MultiEnvMailerConfig added in v1.0.0

type MultiEnvMailerConfig = MultiEnvConfig[MailerConfig]

type MultiEnvOAuthConfig added in v1.0.0

type MultiEnvOAuthConfig = MultiEnvConfig[OAuthConfig]

type MultiEnvPaymentConfig added in v1.0.0

type MultiEnvPaymentConfig = MultiEnvConfig[PaymentConfig]

type MultiEnvServerConfig added in v1.0.0

type MultiEnvServerConfig = MultiEnvConfig[ServerConfig]

type OAuthConfig

type OAuthConfig struct {
	ClientID     string // OAuth client ID
	ClientSecret string // OAuth client secret
	RedirectURL  string // OAuth redirect URL after authentication
}

OAuthConfig holds OAuth 2.0 client credentials and redirect URL.

func LoadEnvOAuthConfig

func LoadEnvOAuthConfig(prefix ...string) (*OAuthConfig, error)

LoadEnvOAuthConfig loads OAuthConfig from environment variables, with an optional prefix.

func NewOAuthConfig

func NewOAuthConfig(clientID, clientSecret, redirectURL string) *OAuthConfig

func (*OAuthConfig) WithClientID

func (cfg *OAuthConfig) WithClientID(clientID string) *OAuthConfig

WithClientID sets the OAuth client ID and returns the updated config.

func (*OAuthConfig) WithClientSecret

func (cfg *OAuthConfig) WithClientSecret(clientSecret string) *OAuthConfig

WithClientSecret sets the OAuth client secret and returns the updated config.

func (*OAuthConfig) WithRedirectURL

func (cfg *OAuthConfig) WithRedirectURL(redirectURL string) *OAuthConfig

WithRedirectURL sets the OAuth redirect URL and returns the updated config.

type PaymentConfig

type PaymentConfig struct {
	APIKey        string // Public API key for the payment provider
	SecretKey     string // Secret key for authenticating requests
	WebhookURL    string // URL to receive payment provider webhook callbacks
	WebhookSecret string // Secret used to verify webhook authenticity
}

PaymentConfig holds configuration details for payment processing.

func LoadEnvPaymentConfig

func LoadEnvPaymentConfig(prefix ...string) (*PaymentConfig, error)

LoadEnvPaymentConfig loads PaymentConfig from environment variables, optionally with a prefix.

func NewPaymentConfig

func NewPaymentConfig(apiKey, secretKey, url, webhookSecret string) *PaymentConfig

func (*PaymentConfig) WithAPIKey

func (cfg *PaymentConfig) WithAPIKey(key string) *PaymentConfig

WithAPIKey sets the API key and returns the updated config.

func (*PaymentConfig) WithSecretKey

func (cfg *PaymentConfig) WithSecretKey(secret string) *PaymentConfig

WithSecretKey sets the secret key and returns the updated config.

func (*PaymentConfig) WithWebhookSecret

func (cfg *PaymentConfig) WithWebhookSecret(secret string) *PaymentConfig

WithWebhookSecret sets the webhook secret and returns the updated config.

func (*PaymentConfig) WithWebhookURL

func (cfg *PaymentConfig) WithWebhookURL(url string) *PaymentConfig

WithWebhookURL sets the webhook URL and returns the updated config.

type ServerConfig added in v1.0.0

type ServerConfig struct {
	Port         string        // Port on which the server listens
	ReadTimeout  time.Duration // Maximum duration for reading the entire request
	WriteTimeout time.Duration // Maximum duration before timing out writes
	IdleTimeout  time.Duration // Maximum time to wait for the next request
}

ServerConfig contains configuration settings for an server.

func LoadEnvServerConfig added in v1.0.0

func LoadEnvServerConfig(prefix ...string) (*ServerConfig, error)

LoadEnvServerConfig loads server config values from environment variables. The env var keys are prefixed with the optional prefix argument.

func NewServerConfig added in v1.0.0

func NewServerConfig(port string, read, write, idle time.Duration) *ServerConfig

func (*ServerConfig) WithIdleTimeout added in v1.0.0

func (cfg *ServerConfig) WithIdleTimeout(timeout time.Duration) *ServerConfig

WithIdleTimeout sets the IdleTimeout field and returns the updated ServerConfig.

func (*ServerConfig) WithPort added in v1.0.0

func (cfg *ServerConfig) WithPort(port string) *ServerConfig

WithPort sets the Port field and returns the updated ServerConfig.

func (*ServerConfig) WithReadTimeout added in v1.0.0

func (cfg *ServerConfig) WithReadTimeout(timeout time.Duration) *ServerConfig

WithReadTimeout sets the ReadTimeout field and returns the updated ServerConfig.

func (*ServerConfig) WithWriteTimeout added in v1.0.0

func (cfg *ServerConfig) WithWriteTimeout(timeout time.Duration) *ServerConfig

WithWriteTimeout sets the WriteTimeout field and returns the updated ServerConfig.

Jump to

Keyboard shortcuts

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