{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package config\n\n## Functions\n\n```go\nfunc GetIPs() (hostname string, ipList string, ipNetList []net.IP)\n```\nGetIPs returns the hostname, a comma-separated list of non-loopback IPs and the same IPs as \\[]net.IP. The lookup is bounded by a short timeout.\n\n```go\nfunc SetConfigManager(m *Manager)\n```\nSetConfigManager publishes m as the global manager returned by GetConfigManager. NewManager no longer does this implicitly.\n\n## Types\n\n```go\ntype CORSConfig struct {\n\tAllowedOrigins []string `mapstructure:\"allowed_origins\"`\n\tAllowedMethods []string `mapstructure:\"allowed_methods\"`\n\tAllowedHeaders []string `mapstructure:\"allowed_headers\"`\n\tMaxAge         int      `mapstructure:\"max_age\"`\n}\n```\nCORSConfig holds CORS configuration\n\n```go\ntype CacheConfig struct {\n\tProvider string         `mapstructure:\"provider\"` // memory, redis, memcache\n\tRedis    RedisConfig    `mapstructure:\"redis\"`\n\tMemcache MemcacheConfig `mapstructure:\"memcache\"`\n}\n```\nCacheConfig holds cache provider configuration\n\n```go\ntype Config struct {\n\tServers       ServersConfig          `mapstructure:\"servers\"`\n\tTracing       TracingConfig          `mapstructure:\"tracing\"`\n\tCache         CacheConfig            `mapstructure:\"cache\"`\n\tLogger        LoggerConfig           `mapstructure:\"logger\"`\n\tErrorTracking ErrorTrackingConfig    `mapstructure:\"error_tracking\"`\n\tMiddleware    MiddlewareConfig       `mapstructure:\"middleware\"`\n\tCORS          CORSConfig             `mapstructure:\"cors\"`\n\tEventBroker   EventBrokerConfig      `mapstructure:\"event_broker\"`\n\tDBManager     DBManagerConfig        `mapstructure:\"dbmanager\"`\n\tDBTrace       DBTraceConfig          `mapstructure:\"db_trace\"`\n\tHardening     HardeningConfig        `mapstructure:\"hardening\"`\n\tPaths         PathsConfig            `mapstructure:\"paths\"`\n\tExtensions    map[string]interface{} `mapstructure:\"extensions\"`\n}\n```\nConfig represents the complete application configuration\n\n```go\nfunc (c *Config) Validate() error\n```\nValidate checks every configuration section for invalid or unsafe values.\n\n```go\ntype DBConnectionConfig struct {\n\t// Name is the unique name of this connection\n\tName string `mapstructure:\"name\"`\n\n\t// Type is the database type (postgres, sqlite, mssql, mongodb)\n\tType string `mapstructure:\"type\"`\n\n\t// DSN is the complete Data Source Name / connection string\n\t// If provided, this takes precedence over individual connection parameters\n\tDSN string `mapstructure:\"dsn\"`\n\n\t// Connection parameters (used if DSN is not provided)\n\tHost     string `mapstructure:\"host\"`\n\tPort     int    `mapstructure:\"port\"`\n\tUser     string `mapstructure:\"user\"`\n\tPassword string `mapstructure:\"password\"`\n\tDatabase string `mapstructure:\"database\"`\n\n\t// PostgreSQL/MSSQL specific\n\tSSLMode string `mapstructure:\"sslmode\"` // disable, require, verify-ca, verify-full\n\tSchema  string `mapstructure:\"schema\"`  // Default schema\n\n\t// ApplicationName identifies this client to the server (postgres\n\t// application_name, mssql app name, mongodb appName)\n\tApplicationName string `mapstructure:\"application_name\"`\n\n\t// SQLite specific\n\tFilePath string `mapstructure:\"filepath\"`\n\n\t// MongoDB specific\n\tAuthSource     string `mapstructure:\"auth_source\"`\n\tReplicaSet     string `mapstructure:\"replica_set\"`\n\tReadPreference string `mapstructure:\"read_preference\"` // primary, secondary, etc.\n\n\t// Connection pool settings (overrides global defaults)\n\tMaxOpenConns    *int           `mapstructure:\"max_open_conns\"`\n\tMaxIdleConns    *int           `mapstructure:\"max_idle_conns\"`\n\tConnMaxLifetime *time.Duration `mapstructure:\"conn_max_lifetime\"`\n\tConnMaxIdleTime *time.Duration `mapstructure:\"conn_max_idle_time\"`\n\n\t// Timeouts\n\tConnectTimeout time.Duration `mapstructure:\"connect_timeout\"`\n\tQueryTimeout   time.Duration `mapstructure:\"query_timeout\"`\n\n\t// Features\n\tEnableTracing bool `mapstructure:\"enable_tracing\"`\n\tEnableMetrics bool `mapstructure:\"enable_metrics\"`\n\tEnableLogging bool `mapstructure:\"enable_logging\"`\n\n\t// DefaultORM specifies which ORM to use for the Database() method\n\t// Options: \"bun\", \"gorm\", \"native\"\n\tDefaultORM string `mapstructure:\"default_orm\"`\n\n\t// Tags for organization and filtering\n\tTags map[string]string `mapstructure:\"tags\"`\n}\n```\nDBConnectionConfig defines configuration for a single database connection\n\n```go\nfunc (cc *DBConnectionConfig) PopulateFromDSN() error\n```\nPopulateFromDSN parses a DSN and populates the connection fields\n\n```go\ntype DBManagerConfig struct {\n\t// DefaultConnection is the name of the default connection to use\n\tDefaultConnection string `mapstructure:\"default_connection\"`\n\n\t// Connections is a map of connection name to connection configuration\n\tConnections map[string]DBConnectionConfig `mapstructure:\"connections\"`\n\n\t// Global connection pool defaults\n\tMaxOpenConns    int           `mapstructure:\"max_open_conns\"`\n\tMaxIdleConns    int           `mapstructure:\"max_idle_conns\"`\n\tConnMaxLifetime time.Duration `mapstructure:\"conn_max_lifetime\"`\n\tConnMaxIdleTime time.Duration `mapstructure:\"conn_max_idle_time\"`\n\n\t// Retry policy\n\tRetryAttempts int           `mapstructure:\"retry_attempts\"`\n\tRetryDelay    time.Duration `mapstructure:\"retry_delay\"`\n\tRetryMaxDelay time.Duration `mapstructure:\"retry_max_delay\"`\n\n\t// Health checks\n\tHealthCheckInterval time.Duration `mapstructure:\"health_check_interval\"`\n\tEnableAutoReconnect bool          `mapstructure:\"enable_auto_reconnect\"`\n}\n```\nDBManagerConfig contains configuration for the database connection manager\n\n```go\nfunc (c *DBManagerConfig) ToManagerConfig() interface{}\n```\nToManagerConfig converts config.DBManagerConfig to dbmanager.ManagerConfig This is used to avoid circular dependencies\n\n```go\nfunc (c *DBManagerConfig) Validate() error\n```\nValidate validates the DBManager configuration\n\n```go\ntype DBTraceConfig struct {\n\tEnabled     bool          `mapstructure:\"enabled\"`      // per-request DB call logging\n\tMinCalls    int           `mapstructure:\"min_calls\"`    // log requests with at least this many DB calls\n\tMinDuration time.Duration `mapstructure:\"min_duration\"` // or that took at least this long (0 = off)\n\tPoolLog     bool          `mapstructure:\"pool_log\"`     // log pool changes on each metrics publish\n}\n```\nDBTraceConfig controls database usage logging (off by default). Env: RESOLVESPEC\\_DB\\_TRACE\\_ENABLED, \\_MIN\\_CALLS, \\_MIN\\_DURATION, \\_POOL\\_LOG.\n\n```go\ntype ErrorTrackingConfig struct {\n\tEnabled          bool    `mapstructure:\"enabled\"`\n\tProvider         string  `mapstructure:\"provider\"`           // sentry, noop\n\tDSN              string  `mapstructure:\"dsn\"`                // Sentry DSN\n\tEnvironment      string  `mapstructure:\"environment\"`        // e.g., production, staging, development\n\tRelease          string  `mapstructure:\"release\"`            // Application version/release\n\tDebug            bool    `mapstructure:\"debug\"`              // Enable debug mode\n\tSampleRate       float64 `mapstructure:\"sample_rate\"`        // Error sample rate (0.0-1.0)\n\tTracesSampleRate float64 `mapstructure:\"traces_sample_rate\"` // Traces sample rate (0.0-1.0)\n}\n```\nErrorTrackingConfig holds error tracking configuration\n\n```go\ntype EventBrokerConfig struct {\n\tEnabled     bool                         `mapstructure:\"enabled\"`\n\tProvider    string                       `mapstructure:\"provider\"` // memory, redis, nats, database\n\tMode        string                       `mapstructure:\"mode\"`     // sync, async\n\tWorkerCount int                          `mapstructure:\"worker_count\"`\n\tBufferSize  int                          `mapstructure:\"buffer_size\"`\n\tInstanceID  string                       `mapstructure:\"instance_id\"`\n\tRedis       EventBrokerRedisConfig       `mapstructure:\"redis\"`\n\tNATS        EventBrokerNATSConfig        `mapstructure:\"nats\"`\n\tDatabase    EventBrokerDatabaseConfig    `mapstructure:\"database\"`\n\tRetryPolicy EventBrokerRetryPolicyConfig `mapstructure:\"retry_policy\"`\n}\n```\nEventBrokerConfig contains configuration for the event broker\n\n```go\ntype EventBrokerDatabaseConfig struct {\n\tTableName    string        `mapstructure:\"table_name\"`\n\tChannel      string        `mapstructure:\"channel\"` // PostgreSQL NOTIFY channel name\n\tPollInterval time.Duration `mapstructure:\"poll_interval\"`\n}\n```\nEventBrokerDatabaseConfig contains database provider configuration\n\n```go\ntype EventBrokerNATSConfig struct {\n\tURL        string        `mapstructure:\"url\"`\n\tStreamName string        `mapstructure:\"stream_name\"`\n\tSubjects   []string      `mapstructure:\"subjects\"`\n\tStorage    string        `mapstructure:\"storage\"` // file, memory\n\tMaxAge     time.Duration `mapstructure:\"max_age\"`\n}\n```\nEventBrokerNATSConfig contains NATS-specific configuration\n\n```go\ntype EventBrokerRedisConfig struct {\n\tStreamName    string `mapstructure:\"stream_name\"`\n\tConsumerGroup string `mapstructure:\"consumer_group\"`\n\tMaxLen        int64  `mapstructure:\"max_len\"`\n\tHost          string `mapstructure:\"host\"`\n\tPort          int    `mapstructure:\"port\"`\n\tPassword      string `mapstructure:\"password\"`\n\tDB            int    `mapstructure:\"db\"`\n}\n```\nEventBrokerRedisConfig contains Redis-specific configuration\n\n```go\ntype EventBrokerRetryPolicyConfig struct {\n\tMaxRetries    int           `mapstructure:\"max_retries\"`\n\tInitialDelay  time.Duration `mapstructure:\"initial_delay\"`\n\tMaxDelay      time.Duration `mapstructure:\"max_delay\"`\n\tBackoffFactor float64       `mapstructure:\"backoff_factor\"`\n}\n```\nEventBrokerRetryPolicyConfig contains retry policy configuration\n\n```go\ntype HardeningConfig struct {\n\t// CORSStrictOrigins only reflects origins listed in cors.allowed_origins (and the\n\t// server URLs); credentials are never sent for unlisted or wildcard origins.\n\tCORSStrictOrigins bool `mapstructure:\"cors_strict_origins\"`\n\t// SortStrict stops empty/substring join aliases from admitting arbitrary sort strings.\n\tSortStrict bool `mapstructure:\"sort_strict\"`\n\t// SQLStrict hardens client raw-SQL fragments (x-custom-sql-*, preload where, cursor):\n\t// balanced parentheses, no subqueries/functions/comments, and rejection instead of\n\t// silently dropping the filter.\n\tSQLStrict bool `mapstructure:\"sql_strict\"`\n\t// SQLBlockSubqueries additionally rejects subqueries (select/union/with) in client\n\t// WHERE fragments (not custom joins). Off by default: existing clients use them.\n\tSQLBlockSubqueries bool `mapstructure:\"sql_block_subqueries\"`\n}\n```\nHardeningConfig toggles security hardening that may reject requests which older clients relied on. All switches default to true; set one to false to restore the previous (permissive) behaviour. Env: RESOLVESPEC\\_HARDENING\\_CORS\\_STRICT\\_ORIGINS, \\_SORT\\_STRICT, \\_SQL\\_STRICT, \\_SQL\\_BLOCK\\_SUBQUERIES.\n\n```go\ntype LoggerConfig struct {\n\tDev  bool   `mapstructure:\"dev\"`\n\tPath string `mapstructure:\"path\"`\n}\n```\nLoggerConfig holds logger configuration\n\n```go\ntype Manager struct {\n\t// contains filtered or unexported fields\n}\n```\nManager handles configuration loading from multiple sources. viper.Viper is not safe for concurrent use, so every access to it is guarded by mu.\n\n```go\nfunc GetConfigManager() *Manager\n```\nGetConfigManager returns a singleton configuration manager instance\n\n```go\nfunc NewManager() *Manager\n```\nNewManager creates a new, isolated configuration manager with defaults. It does not replace the global manager; use SetConfigManager for that.\n\n```go\nfunc NewManagerWithOptions(opts ...Option) *Manager\n```\nNewManagerWithOptions creates a new configuration manager with custom options\n\n```go\nfunc (m *Manager) ConfigFileUsed() string\n```\nConfigFileUsed returns the config file that was read by Load, or \"\" if none was found (i.e. the manager is running on defaults and environment variables only).\n\n```go\nfunc (m *Manager) Get(key string) interface{}\n```\nGet returns a configuration value by key\n\n```go\nfunc (m *Manager) GetBool(key string) bool\n```\nGetBool returns a bool configuration value\n\n```go\nfunc (m *Manager) GetConfig() (*Config, error)\n```\nGetConfig returns the complete configuration\n\n```go\nfunc (m *Manager) GetInt(key string) int\n```\nGetInt returns an int configuration value\n\n```go\nfunc (m *Manager) GetString(key string) string\n```\nGetString returns a string configuration value\n\n```go\nfunc (m *Manager) Load() error\n```\nLoad attempts to load configuration from file and environment. A missing config file is not an error (defaults and env vars are used); check ConfigFileUsed after Load to see whether a file was actually read.\n\n```go\nfunc (m *Manager) SaveConfig(path string) error\n```\nSaveConfig writes the current configuration to the specified path. The file contains the entire merged configuration, including secrets (database/redis passwords, error-tracking DSN), so it is written with mode 0600. Prefer supplying secrets via RESOLVESPEC\\_\\* environment variables.\n\n```go\nfunc (m *Manager) Set(key string, value interface{})\n```\nSet sets a configuration value\n\n```go\nfunc (m *Manager) SetConfig(cfg *Config) error\n```\nSetConfig sets the complete configuration atomically\n\n```go\ntype MemcacheConfig struct {\n\tServers      []string      `mapstructure:\"servers\"`\n\tMaxIdleConns int           `mapstructure:\"max_idle_conns\"`\n\tTimeout      time.Duration `mapstructure:\"timeout\"`\n}\n```\nMemcacheConfig holds Memcache-specific configuration\n\n```go\ntype MiddlewareConfig struct {\n\tRateLimitRPS   float64 `mapstructure:\"rate_limit_rps\"`\n\tRateLimitBurst int     `mapstructure:\"rate_limit_burst\"`\n\tMaxRequestSize int64   `mapstructure:\"max_request_size\"`\n}\n```\nMiddlewareConfig holds middleware configuration\n\n```go\ntype Option func(*Manager)\n```\nOption is a functional option for configuring the Manager\n\n```go\nfunc WithConfigFile(path string) Option\n```\nWithConfigFile sets a specific config file path\n\n```go\nfunc WithConfigName(name string) Option\n```\nWithConfigName sets the config file name (without extension)\n\n```go\nfunc WithConfigPath(path string) Option\n```\nWithConfigPath adds a path to search for config files\n\n```go\nfunc WithEnvPrefix(prefix string) Option\n```\nWithEnvPrefix sets the environment variable prefix\n\n```go\ntype PathsConfig map[string]string\n```\nPathsConfig contains configuration for named file system paths This is a map of path name to file system path Example: \"data\\_dir\": \"/var/lib/myapp/data\"\n\n```go\nfunc (pc PathsConfig) AbsPath(name string) (string, error)\n```\nAbsPath returns the absolute path for a named path\n\n```go\nfunc (pc PathsConfig) EnsureDir(name string, perm os.FileMode) error\n```\nEnsureDir ensures a directory exists at the specified path name Creates the directory if it doesn't exist with the given permissions\n\n```go\nfunc (pc PathsConfig) Get(name string) (string, error)\n```\nGet retrieves a path by name\n\n```go\nfunc (pc PathsConfig) GetOrDefault(name, defaultPath string) string\n```\nGetOrDefault retrieves a path by name, returning defaultPath if not found\n\n```go\nfunc (pc PathsConfig) Has(name string) bool\n```\nHas checks if a path exists by name\n\n```go\nfunc (pc PathsConfig) Join(name string, elem ...string) (string, error)\n```\nJoin joins path segments with a named base path. It returns an error if the result would escape the base path.\n\n```go\nfunc (pc PathsConfig) List() []string\n```\nList returns all configured path names\n\n```go\nfunc (pc *PathsConfig) Set(name, path string)\n```\nSet sets a path by name. It takes a pointer so a nil map can be allocated. PathsConfig is not safe for concurrent mutation; populate it before sharing.\n\n```go\ntype RedisConfig struct {\n\tHost     string `mapstructure:\"host\"`\n\tPort     int    `mapstructure:\"port\"`\n\tPassword string `mapstructure:\"password\"`\n\tDB       int    `mapstructure:\"db\"`\n}\n```\nRedisConfig holds Redis-specific configuration\n\n```go\ntype ServerInstanceConfig struct {\n\t// Name is the unique name of this server instance\n\tName string `mapstructure:\"name\"`\n\n\t// Host is the host to bind to (e.g., \"localhost\", \"0.0.0.0\", \"\")\n\tHost string `mapstructure:\"host\"`\n\n\t// Port is the port number to listen on\n\tPort int `mapstructure:\"port\"`\n\n\t// Description is a human-readable description of this server\n\tDescription string `mapstructure:\"description\"`\n\n\t// GZIP enables GZIP compression middleware\n\tGZIP bool `mapstructure:\"gzip\"`\n\n\t// HTTP2 enables HTTP/2 with the Extended CONNECT protocol (RFC 8441) for WebSocket support.\n\t// Requires TLS; pair with SSLCert/SSLKey, SelfSignedSSL, or AutoTLS.\n\tHTTP2 bool `mapstructure:\"http2\"`\n\n\t// TLS/HTTPS configuration options (mutually exclusive)\n\t// Option 1: Provide certificate and key files directly\n\tSSLCert string `mapstructure:\"ssl_cert\"`\n\tSSLKey  string `mapstructure:\"ssl_key\"`\n\n\t// Option 2: Use self-signed certificate (for development/testing)\n\tSelfSignedSSL bool `mapstructure:\"self_signed_ssl\"`\n\n\t// Option 3: Use Let's Encrypt / AutoTLS\n\tAutoTLS         bool     `mapstructure:\"auto_tls\"`\n\tAutoTLSDomains  []string `mapstructure:\"auto_tls_domains\"`\n\tAutoTLSCacheDir string   `mapstructure:\"auto_tls_cache_dir\"`\n\tAutoTLSEmail    string   `mapstructure:\"auto_tls_email\"`\n\n\t// Timeout configurations (overrides global defaults)\n\tShutdownTimeout *time.Duration `mapstructure:\"shutdown_timeout\"`\n\tDrainTimeout    *time.Duration `mapstructure:\"drain_timeout\"`\n\tReadTimeout     *time.Duration `mapstructure:\"read_timeout\"`\n\tWriteTimeout    *time.Duration `mapstructure:\"write_timeout\"`\n\tIdleTimeout     *time.Duration `mapstructure:\"idle_timeout\"`\n\n\t// Tags for organization and filtering\n\tTags map[string]string `mapstructure:\"tags\"`\n\n\t// ExternalURLs are additional URLs that this server instance is accessible from (for CORS) for proxy setups\n\tExternalURLs []string `mapstructure:\"external_urls\"`\n}\n```\nServerInstanceConfig defines configuration for a single server instance\n\n```go\nfunc (sic *ServerInstanceConfig) ApplyGlobalDefaults(globals ServersConfig)\n```\nApplyGlobalDefaults applies global server defaults to this instance Called for instances that don't specify their own timeout values\n\n```go\nfunc (sic *ServerInstanceConfig) Validate() error\n```\nValidate validates the ServerInstanceConfig\n\n```go\ntype ServersConfig struct {\n\t// DefaultServer is the name of the default server to use\n\tDefaultServer string `mapstructure:\"default_server\"`\n\n\t// Instances is a map of server name to server configuration\n\tInstances map[string]ServerInstanceConfig `mapstructure:\"instances\"`\n\n\t// Global timeout defaults (can be overridden per instance)\n\tShutdownTimeout time.Duration `mapstructure:\"shutdown_timeout\"`\n\tDrainTimeout    time.Duration `mapstructure:\"drain_timeout\"`\n\tReadTimeout     time.Duration `mapstructure:\"read_timeout\"`\n\tWriteTimeout    time.Duration `mapstructure:\"write_timeout\"`\n\tIdleTimeout     time.Duration `mapstructure:\"idle_timeout\"`\n}\n```\nServersConfig contains configuration for the server manager\n\n```go\nfunc (sc *ServersConfig) GetDefault() (*ServerInstanceConfig, error)\n```\nGetDefault returns the default server instance configuration. The returned pointer refers to a copy: mutating it does not modify sc.Instances.\n\n```go\nfunc (sc *ServersConfig) Validate() error\n```\nValidate validates the ServersConfig\n\n```go\ntype TracingConfig struct {\n\tEnabled        bool   `mapstructure:\"enabled\"`\n\tServiceName    string `mapstructure:\"service_name\"`\n\tServiceVersion string `mapstructure:\"service_version\"`\n\tEndpoint       string `mapstructure:\"endpoint\"`\n\t// Insecure exports traces over plaintext gRPC (default false: TLS).\n\tInsecure bool `mapstructure:\"insecure\"`\n\t// SampleRate is the fraction of root traces sampled; 0 selects the default (0.1).\n\tSampleRate float64 `mapstructure:\"sample_rate\"`\n\t// Headers are sent with every OTLP export request (e.g. auth tokens).\n\tHeaders map[string]string `mapstructure:\"headers\"`\n}\n```\nTracingConfig holds OpenTelemetry tracing configuration\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/config","name":"config","synopsis":"","isRedistributable":true}
