package config func newAppConfig() *AppConfig { return &AppConfig{ Version: getVersion(), Logging: &LogConfig{}, HTTP: &HTTPConfig{}, OTEL: &OTELConfig{}, } } type AppConfig struct { Name string `yaml:"name" env:"APP_NAME" envDefault:"go-http-server-with-otel"` Environment string `yaml:"environment" env:"APP_ENVIRONMENT" envDefault:"development"` // This should either be set by ldflags, such as with // go build -ldflags "-X gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config.Version=$(VERSION)" // or allow this to use build meta. Will default to (devel) Version string `yaml:"version" env:"APP_VERSION"` Logging *LogConfig `yaml:"logging"` HTTP *HTTPConfig `yaml:"http"` OTEL *OTELConfig `yaml:"otel"` } // Logging Configuration type LogConfig struct { Enabled bool `yaml:"enabled" env:"APP_LOG_ENABLED" envDefault:"true"` Level string `yaml:"level" env:"APP_LOG_LEVEL" envDefault:"info"` Format LogFormat `yaml:"format" env:"APP_LOG_FORMAT" envDefault:"json"` Output LogOutput `yaml:"output" env:"APP_LOG_OUTPUT" envDefault:"stderr"` TimeFormat TimeFormat `yaml:"timeFormat" env:"APP_LOG_TIME_FORMAT" envDefault:"short"` } 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" env:"APP_HTTP_LISTEN" envDefault:"127.0.0.1:8080"` RequestTimeout int `yaml:"requestTimeout" env:"APP_HTTP_REQUEST_TIMEOUT" envDefault:"30"` } // OTEL Configuration type OTELConfig struct { Enabled bool `yaml:"enabled" env:"APP_OTEL_ENABLED" envDefault:"true"` PrometheusEnabled bool `yaml:"prometheusEnabled" env:"APP_OTEL_PROMETHEUS_ENABLED" envDefault:"true"` PrometheusPath string `yaml:"prometheusPath" env:"APP_OTEL_PROMETHEUS_PATH" envDefault:"/metrics"` StdoutEnabled bool `yaml:"stdoutEnabled" env:"APP_OTEL_STDOUT_ENABLED" envDefault:"false"` MetricIntervalSecs int `yaml:"metricIntervalSecs" env:"APP_OTEL_METRIC_INTERVAL_SECS" envDefault:"15"` }