package config // Default Settings var DefaultConfig = &AppConfig{ Environment: "development", Version: getVersion(), Logging: &LogConfig{ Enabled: true, Level: "info", Format: LogFormatJSON, Output: "stderr", TimeFormat: TimeFormatLong, }, HTTP: &HTTPConfig{ Listen: "127.0.0.1:8080", }, OTEL: &OTELConfig{ Enabled: true, PrometheusEnabled: true, PrometheusPath: "/metrics", StdoutEnabled: false, MetricIntervalSecs: 30, }, } type AppConfig struct { Name string `yaml:"name,omitempty" env:"APP_NAME"` Environment string `yaml:"environment,omitempty" env:"APP_ENVIRONMENT"` // This should either be set by ldflags, such as with // go build -ldflags "-X gitea.libretechconsulting.com/rmcguire/go-app/pkg/config.Version=$(VERSION)" // or allow this to use build meta. Will default to (devel) Version string `yaml:"version,omitempty" env:"APP_VERSION"` Logging *LogConfig `yaml:"logging,omitempty"` HTTP *HTTPConfig `yaml:"http,omitempty"` OTEL *OTELConfig `yaml:"otel,omitempty"` } // Logging Configuration type LogConfig struct { Enabled bool `yaml:"enabled,omitempty" env:"APP_LOG_ENABLED"` Level string `yaml:"level,omitempty" env:"APP_LOG_LEVEL"` Format LogFormat `yaml:"format,omitempty" env:"APP_LOG_FORMAT"` Output LogOutput `yaml:"output,omitempty" env:"APP_LOG_OUTPUT"` TimeFormat TimeFormat `yaml:"timeFormat,omitempty" env:"APP_LOG_TIME_FORMAT"` } type LogFormat string const ( LogFormatConsole LogFormat = "console" LogFormatJSON LogFormat = "json" ) type TimeFormat string const ( TimeFormatShort TimeFormat = "short" TimeFormatLong TimeFormat = "long" TimeFormatUnix TimeFormat = "unix" TimeFormatRFC3339 TimeFormat = "rfc3339" TimeFormatOff TimeFormat = "off" ) type LogOutput string const ( LogOutputStdout LogOutput = "stdout" LogOutputStderr LogOutput = "stderr" ) // HTTP Configuration type HTTPConfig struct { Listen string `yaml:"listen,omitempty" env:"APP_HTTP_LISTEN"` RequestTimeout int `yaml:"requestTimeout,omitempty" env:"APP_HTTP_REQUEST_TIMEOUT"` } // OTEL Configuration type OTELConfig struct { Enabled bool `yaml:"enabled,omitempty" env:"APP_OTEL_ENABLED"` PrometheusEnabled bool `yaml:"prometheusEnabled,omitempty" env:"APP_OTEL_PROMETHEUS_ENABLED"` PrometheusPath string `yaml:"prometheusPath,omitempty" env:"APP_OTEL_PROMETHEUS_PATH"` StdoutEnabled bool `yaml:"stdoutEnabled,omitempty" env:"APP_OTEL_STDOUT_ENABLED"` MetricIntervalSecs int `yaml:"metricIntervalSecs,omitempty" env:"APP_OTEL_METRIC_INTERVAL_SECS"` }