support json schema

This commit is contained in:
2025-03-22 14:02:39 -04:00
parent f0a699029a
commit 3e319b24fd
10 changed files with 82 additions and 36 deletions

View File

@ -11,16 +11,16 @@ var DefaultConfig = &AppConfig{
}
type AppConfig struct {
Name string `yaml:"name,omitempty" env:"APP_NAME"`
Environment string `yaml:"environment,omitempty" env:"APP_ENVIRONMENT"`
Name string `yaml:"name,omitempty" env:"APP_NAME" json:"name,omitempty"`
Environment string `yaml:"environment,omitempty" env:"APP_ENVIRONMENT" json:"environment,omitempty"`
// 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"`
GRPC *GRPCConfig `yaml:"grpc,omitempty"`
Version string `yaml:"version,omitempty" env:"APP_VERSION" json:"version,omitempty"`
Logging *LogConfig `yaml:"logging,omitempty" json:"logging,omitempty"`
HTTP *HTTPConfig `yaml:"http,omitempty" json:"http,omitempty"`
OTEL *OTELConfig `yaml:"otel,omitempty" json:"otel,omitempty"`
GRPC *GRPCConfig `yaml:"grpc,omitempty" json:"grpc,omitempty"`
}
func (ac *AppConfig) HTTPEnabled() bool {

View File

@ -10,9 +10,9 @@ var defaultGRPCConfig = &GRPCConfig{
}
type GRPCConfig struct {
Enabled bool `yaml:"enabled" env:"APP_GRPC_ENABLED"`
Listen string `yaml:"listen" env:"APP_GRPC_LISTEN"`
LogRequests bool `yaml:"logRequests" env:"APP_GRPC_LOG_REQUESTS"`
EnableReflection bool `yaml:"enableReflection" env:"APP_GRPC_ENABLE_REFLECTION"`
EnableInstrumentation bool `yaml:"enableInstrumentation" env:"APP_GRPC_ENABLE_INSTRUMENTATION"` // requires OTEL
Enabled bool `yaml:"enabled" env:"APP_GRPC_ENABLED" json:"enabled,omitempty"`
Listen string `yaml:"listen" env:"APP_GRPC_LISTEN" json:"listen,omitempty"`
LogRequests bool `yaml:"logRequests" env:"APP_GRPC_LOG_REQUESTS" json:"logRequests,omitempty"`
EnableReflection bool `yaml:"enableReflection" env:"APP_GRPC_ENABLE_REFLECTION" json:"enableReflection,omitempty"`
EnableInstrumentation bool `yaml:"enableInstrumentation" env:"APP_GRPC_ENABLE_INSTRUMENTATION" json:"enableInstrumentation,omitempty"` // requires OTEL
}

View File

@ -14,13 +14,13 @@ var defaultHTTPConfig = &HTTPConfig{
// HTTP Configuration
type HTTPConfig struct {
Enabled bool `yaml:"enabled" env:"APP_HTTP_ENABLED"`
Listen string `yaml:"listen,omitempty" env:"APP_HTTP_LISTEN"`
LogRequests bool `yaml:"logRequests" env:"APP_HTTP_LOG_REQUESTS"`
ReadTimeout string `yaml:"readTimeout" env:"APP_HTTP_READ_TIMEOUT"` // Go duration (e.g. 10s)
WriteTimeout string `yaml:"writeTimeout" env:"APP_HTTP_WRITE_TIMEOUT"` // Go duration (e.g. 10s)
IdleTimeout string `yaml:"idleTimeout" env:"APP_HTTP_IDLE_TIMEOUT"` // Go duration (e.g. 10s)
rT *time.Duration `yaml:"rT" env:"rT"`
wT *time.Duration `yaml:"wT" env:"wT"`
iT *time.Duration `yaml:"iT" env:"iT"`
Enabled bool `yaml:"enabled" env:"APP_HTTP_ENABLED" json:"enabled,omitempty"`
Listen string `yaml:"listen,omitempty" env:"APP_HTTP_LISTEN" json:"listen,omitempty"`
LogRequests bool `yaml:"logRequests" env:"APP_HTTP_LOG_REQUESTS" json:"logRequests,omitempty"`
ReadTimeout string `yaml:"readTimeout" env:"APP_HTTP_READ_TIMEOUT" json:"readTimeout,omitempty"` // Go duration (e.g. 10s)
WriteTimeout string `yaml:"writeTimeout" env:"APP_HTTP_WRITE_TIMEOUT" json:"writeTimeout,omitempty"` // Go duration (e.g. 10s)
IdleTimeout string `yaml:"idleTimeout" env:"APP_HTTP_IDLE_TIMEOUT" json:"idleTimeout,omitempty"` // Go duration (e.g. 10s)
rT *time.Duration
wT *time.Duration
iT *time.Duration
}

View File

@ -10,11 +10,11 @@ var defaultLoggingConfig = &LogConfig{
// 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"`
Enabled bool `yaml:"enabled,omitempty" env:"APP_LOG_ENABLED" json:"enabled,omitempty"`
Level string `yaml:"level,omitempty" env:"APP_LOG_LEVEL" json:"level,omitempty"`
Format LogFormat `yaml:"format,omitempty" env:"APP_LOG_FORMAT" json:"format,omitempty"`
Output LogOutput `yaml:"output,omitempty" env:"APP_LOG_OUTPUT" json:"output,omitempty"`
TimeFormat TimeFormat `yaml:"timeFormat,omitempty" env:"APP_LOG_TIME_FORMAT" json:"timeFormat,omitempty"`
}
type LogFormat string

View File

@ -10,9 +10,9 @@ var defaultOTELConfig = &OTELConfig{
// 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"`
Enabled bool `yaml:"enabled,omitempty" env:"APP_OTEL_ENABLED" json:"enabled,omitempty"`
PrometheusEnabled bool `yaml:"prometheusEnabled,omitempty" env:"APP_OTEL_PROMETHEUS_ENABLED" json:"prometheusEnabled,omitempty"`
PrometheusPath string `yaml:"prometheusPath,omitempty" env:"APP_OTEL_PROMETHEUS_PATH" json:"prometheusPath,omitempty"`
StdoutEnabled bool `yaml:"stdoutEnabled,omitempty" env:"APP_OTEL_STDOUT_ENABLED" json:"stdoutEnabled,omitempty"`
MetricIntervalSecs int `yaml:"metricIntervalSecs,omitempty" env:"APP_OTEL_METRIC_INTERVAL_SECS" json:"metricIntervalSecs,omitempty"`
}