go-app/pkg/config/types.go

46 lines
1.2 KiB
Go
Raw Normal View History

2025-01-04 12:24:42 -05:00
package config
2025-01-05 13:09:59 -05:00
// Default Settings
var DefaultConfig = &AppConfig{
Environment: "development",
Version: getVersion(),
2025-03-06 17:16:27 -05:00
Logging: defaultLoggingConfig,
HTTP: defaultHTTPConfig,
OTEL: defaultOTELConfig,
GRPC: defaultGRPCConfig,
2025-01-04 12:24:42 -05:00
}
type AppConfig struct {
2025-01-05 13:09:59 -05:00
Name string `yaml:"name,omitempty" env:"APP_NAME"`
Environment string `yaml:"environment,omitempty" env:"APP_ENVIRONMENT"`
2025-01-04 12:24:42 -05:00
// 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)
2025-01-05 13:09:59 -05:00
Version string `yaml:"version,omitempty" env:"APP_VERSION"`
Logging *LogConfig `yaml:"logging,omitempty"`
HTTP *HTTPConfig `yaml:"http,omitempty"`
OTEL *OTELConfig `yaml:"otel,omitempty"`
2025-03-06 17:16:27 -05:00
GRPC *GRPCConfig `yaml:"grpc,omitempty"`
2025-01-04 12:24:42 -05:00
}
2025-03-07 17:04:46 -05:00
func (ac *AppConfig) HTTPEnabled() bool {
if ac.HTTP != nil && ac.HTTP.Enabled {
return true
}
return false
}
func (ac *AppConfig) GRPCEnabled() bool {
if ac.GRPC != nil && ac.GRPC.Enabled {
return true
}
return false
}
func (ac *AppConfig) OTELEnabled() bool {
if ac.OTEL != nil && ac.OTEL.Enabled {
return true
}
return false
}