Files
go-app/pkg/config/types.go

49 lines
1.6 KiB
Go

package config
// DefaultConfig provides a default application configuration.
var DefaultConfig = &AppConfig{
Environment: "development",
Version: getVersion(),
Logging: defaultLoggingConfig,
HTTP: defaultHTTPConfig,
OTEL: defaultOTELConfig,
GRPC: defaultGRPCConfig,
}
type AppConfig struct {
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" 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"`
}
// HTTPEnabled returns true if HTTP is enabled in the AppConfig.
func (ac *AppConfig) HTTPEnabled() bool {
if ac.HTTP != nil && ac.HTTP.Enabled {
return true
}
return false
}
// GRPCEnabled returns true if gRPC is enabled in the AppConfig.
func (ac *AppConfig) GRPCEnabled() bool {
if ac.GRPC != nil && ac.GRPC.Enabled {
return true
}
return false
}
// OTELEnabled returns true if OpenTelemetry is enabled in the AppConfig.
func (ac *AppConfig) OTELEnabled() bool {
if ac.OTEL != nil && ac.OTEL.Enabled {
return true
}
return false
}