add grpc support
This commit is contained in:
@ -1,32 +1,13 @@
|
||||
package config
|
||||
|
||||
import "time"
|
||||
|
||||
// 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",
|
||||
LogRequests: false,
|
||||
ReadTimeout: "10s",
|
||||
WriteTimeout: "10s",
|
||||
IdleTimeout: "1m",
|
||||
},
|
||||
OTEL: &OTELConfig{
|
||||
Enabled: true,
|
||||
PrometheusEnabled: true,
|
||||
PrometheusPath: "/metrics",
|
||||
StdoutEnabled: false,
|
||||
MetricIntervalSecs: 30,
|
||||
},
|
||||
Logging: defaultLoggingConfig,
|
||||
HTTP: defaultHTTPConfig,
|
||||
OTEL: defaultOTELConfig,
|
||||
GRPC: defaultGRPCConfig,
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
@ -39,58 +20,5 @@ type AppConfig struct {
|
||||
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"`
|
||||
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
|
||||
wT *time.Duration
|
||||
iT *time.Duration
|
||||
}
|
||||
|
||||
// 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"`
|
||||
GRPC *GRPCConfig `yaml:"grpc,omitempty"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user