Documentation
¶
Overview ¶
Package config provides application configuration loaded from environment variables via cleanenv struct tags. Supports env prefixes, default values, and .env file loading through Load/LoadFromEnvFile.
Index ¶
Constants ¶
View Source
const Mask = "xxxxxx"
Variables ¶
This section is empty.
Functions ¶
func LoadFromEnvFileInto ¶
Types ¶
type Config ¶
type Config struct {
App AppConfig `env-prefix:"APP_"`
API APIConfig `env-prefix:"API_"`
Metrics MetricsConfig `env-prefix:"METRICS_"`
Logging LoggingConfig `env-prefix:"LOGGING_"`
Telemetry TelemetryConfig `env-prefix:"TELEMETRY_"`
Sentry SentryConfig `env-prefix:"SENTRY_"`
Debug bool `env:"DEBUG" env-default:"false"`
Postgres PostgresConfig `env-prefix:"POSTGRES_"`
}
func LoadFromEnvFile ¶
type LoggingConfig ¶
type MetricsConfig ¶
type PostgresConfig ¶
type PostgresConfig struct {
DSN SecretStr `env:"DSN" env-default:""`
// Hosts is a comma-separated list of host:port pars:
//
// Example: "localhost:15432,localhost:15433"
//
// If empty then ConnString() uses Postgres default: "localhost:5432"
Hosts []string `env:"HOSTS" env-default:""`
User string `env:"USER" env-default:"postgres"`
Password SecretStr `env:"PASSWORD" env-default:"postgres"`
Database string `env:"DATABASE" env-default:"postgres"`
// SSLMode
//
// Values:
// - "disable" - only try a non-SSL connection
// - "allow" - first try a non-SSL connection; if that fails, try an SSL connection
// - "prefer" - first try an SSL connection; if that fails, try a non-SSL connection
// - "require" - only try an SSL connection. If a root CA file is present, verify the certificate in the same way as if verify-ca was specified
// - "verify-ca" - only try an SSL connection, and verify that the server certificate is issued by a trusted certificate authority (CA)
// - "verify-full" - only try an SSL connection, verify that the server certificate is issued by a trusted CA and that the requested server host name matches that in the certificate
SSLMode string `env:"SSLMODE" env-default:"prefer"`
// TargetSessionAttrs used to specify the required state of a server before a connection is established.
//
// Useful values:
// - "primary" - server must not be in hot standby mode (master)
// - "standby" - server must be in hot standby mode (replica)
// - "prefer-standby" - first try to find a standby server, but if none of the listed hosts is a standby server, try again in any mode
//
// https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS
TargetSessionAttrs string `env:"TARGET_SESSION_ATTRS" env-default:"primary"`
MaxConns int32 `env:"MAX_CONNS" env-default:"10"`
MinConns int32 `env:"MIN_CONNS" env-default:"0"`
MaxConnLifetime time.Duration `env:"MAX_CONN_LIFETIME" env-default:"1h"`
MaxConnIdleTime time.Duration `env:"MAX_CONN_IDLE_TIME" env-default:"30m"`
HealthCheckPeriod time.Duration `env:"HEALTH_CHECK_PERIOD" env-default:"1m"`
PingTimeout time.Duration `env:"PING_TIMEOUT" env-default:"30s"`
ConnectTimeout time.Duration `env:"CONNECT_TIMEOUT" env-default:"30s"`
PoolName string `env:"POOL_NAME" env-default:""`
SlowQueryThreshold time.Duration `env:"SLOW_QUERY_THRESHOLD" env-default:"0"`
}
func (*PostgresConfig) ConnString ¶
func (c *PostgresConfig) ConnString() string
type SecretStr ¶
type SecretStr string
SecretStr is a string type that masks its value in String() and MarshalJSON/MarshalText to prevent accidental leakage in logs, error messages, or serialization. Use SecretValue() to access the actual string.
func (SecretStr) MarshalJSON ¶
func (SecretStr) MarshalText ¶
func (SecretStr) SecretValue ¶
type SecretURL ¶
type SecretURL string
SecretURL is a string type that masks the userinfo part (user:password) of a URL in String(), MarshalJSON(), and MarshalText() to prevent accidental leakage in logs, error messages, or serialization. Use SecretValue() to access the actual URL string.
func (SecretURL) MarshalJSON ¶
func (SecretURL) MarshalText ¶
func (SecretURL) SecretValue ¶
type SentryConfig ¶
type SentryConfig struct {
DSN SecretURL `env:"DSN" env-default:""`
Levels []string `env:"LEVELS" env-default:"warn,error"`
SampleRate float64 `env:"SAMPLE_RATE" env-default:"1.0"`
FlushTimeout time.Duration `env:"FLUSH_TIMEOUT" env-default:"5s"`
// EnableTracing enables OpenTelemetry tracing via Sentry's OTLP exporter.
// Requires TelemetryConfig.Enabled=true and InitTelemetry called before InitSentry.
// TracingEndpoint may be empty — traces will be sent to Sentry only.
EnableTracing bool `env:"ENABLE_TRACING" env-default:"false"`
// Debug Sentry SDK
Debug bool `env:"DEBUG" env-default:"false"`
}
type TelemetryConfig ¶
type TelemetryConfig struct {
Enabled bool `env:"ENABLED" env-default:"false"`
TracingEndpoint string `env:"TRACING_ENDPOINT" env-default:"localhost:4317"`
SampleRate float64 `env:"SAMPLE_RATE" env-default:"1.0"`
UseTLS bool `env:"USE_TLS" env-default:"false"`
SkipVerifyCA bool `env:"SKIP_VERIFY_CA" env-default:"false"`
CACertPath string `env:"CA_CERT_PATH" env-default:""`
ConnectTimeout time.Duration `env:"CONNECT_TIMEOUT" env-default:"10s"`
}
Click to show internal directories.
Click to hide internal directories.