📝 docs: update comprehensive documentation and project infrastructure
Documentation Updates: - Enhanced AGENTS.md with user authentication details - Updated README.md with authentication API documentation - Added CONTRIBUTING.md guidelines for BDD testing - Version management guide improvements - Local CI/CD testing documentation Project Infrastructure: - Updated .gitignore for new file patterns - Enhanced git hooks documentation - YAML linting configuration - Script improvements and organization - Configuration management updates API Enhancements: - Greet service integration with authentication - Server middleware for JWT validation - Telemetry improvements - Version management utilities Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -13,6 +13,11 @@ import (
|
||||
"dance-lessons-coach/pkg/version"
|
||||
)
|
||||
|
||||
// NewZerologWriter creates a zerolog writer based on configuration
|
||||
func NewZerologWriter() *os.File {
|
||||
return os.Stderr
|
||||
}
|
||||
|
||||
// Config represents the application configuration
|
||||
type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
@@ -20,6 +25,8 @@ type Config struct {
|
||||
Logging LoggingConfig `mapstructure:"logging"`
|
||||
Telemetry TelemetryConfig `mapstructure:"telemetry"`
|
||||
API APIConfig `mapstructure:"api"`
|
||||
Auth AuthConfig `mapstructure:"auth"`
|
||||
Database DatabaseConfig `mapstructure:"database"`
|
||||
}
|
||||
|
||||
// ServerConfig holds server-related configuration
|
||||
@@ -42,11 +49,17 @@ type LoggingConfig struct {
|
||||
|
||||
// TelemetryConfig holds OpenTelemetry-related configuration
|
||||
type TelemetryConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OTLPEndpoint string `mapstructure:"otlp_endpoint"`
|
||||
ServiceName string `mapstructure:"service_name"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
Sampler SamplerConfig `mapstructure:"sampler"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OTLPEndpoint string `mapstructure:"otlp_endpoint"`
|
||||
ServiceName string `mapstructure:"service_name"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
Sampler SamplerConfig `mapstructure:"sampler"`
|
||||
Persistence PersistenceTelemetryConfig `mapstructure:"persistence"`
|
||||
}
|
||||
|
||||
// PersistenceTelemetryConfig holds persistence layer telemetry configuration
|
||||
type PersistenceTelemetryConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
}
|
||||
|
||||
// APIConfig holds API version configuration
|
||||
@@ -54,6 +67,25 @@ type APIConfig struct {
|
||||
V2Enabled bool `mapstructure:"v2_enabled"`
|
||||
}
|
||||
|
||||
// AuthConfig holds authentication configuration
|
||||
type AuthConfig struct {
|
||||
JWTSecret string `mapstructure:"jwt_secret"`
|
||||
AdminMasterPassword string `mapstructure:"admin_master_password"`
|
||||
}
|
||||
|
||||
// DatabaseConfig holds database configuration
|
||||
type DatabaseConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"port"`
|
||||
User string `mapstructure:"user"`
|
||||
Password string `mapstructure:"password"`
|
||||
Name string `mapstructure:"name"`
|
||||
SSLMode string `mapstructure:"ssl_mode"`
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"`
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
||||
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
|
||||
}
|
||||
|
||||
// VersionInfo holds application version information
|
||||
type VersionInfo struct {
|
||||
Version string `mapstructure:"-"` // Set via ldflags
|
||||
@@ -65,7 +97,7 @@ type VersionInfo struct {
|
||||
// VersionCommand handles version display
|
||||
func (c *Config) VersionCommand() string {
|
||||
// This will be enhanced when we integrate with cobra
|
||||
return fmt.Sprintf("DanceLessonsCoach %s (commit: %s, built: %s, go: %s)",
|
||||
return fmt.Sprintf("dance-lessons-coach %s (commit: %s, built: %s, go: %s)",
|
||||
version.Version, version.Commit, version.Date, version.GoVersion)
|
||||
}
|
||||
|
||||
@@ -96,14 +128,19 @@ func LoadConfig() (*Config, error) {
|
||||
// Telemetry defaults
|
||||
v.SetDefault("telemetry.enabled", false)
|
||||
v.SetDefault("telemetry.otlp_endpoint", "localhost:4317")
|
||||
v.SetDefault("telemetry.service_name", "DanceLessonsCoach")
|
||||
v.SetDefault("telemetry.service_name", "dance-lessons-coach")
|
||||
v.SetDefault("telemetry.insecure", true)
|
||||
v.SetDefault("telemetry.sampler.type", "parentbased_always_on")
|
||||
v.SetDefault("telemetry.sampler.ratio", 1.0)
|
||||
v.SetDefault("telemetry.persistence.enabled", false)
|
||||
|
||||
// API defaults
|
||||
v.SetDefault("api.v2_enabled", false)
|
||||
|
||||
// Auth defaults
|
||||
v.SetDefault("auth.jwt_secret", "default-secret-key-please-change-in-production")
|
||||
v.SetDefault("auth.admin_master_password", "admin123")
|
||||
|
||||
// Check for custom config file path via environment variable
|
||||
if configFile := os.Getenv("DLC_CONFIG_FILE"); configFile != "" {
|
||||
v.SetConfigFile(configFile)
|
||||
@@ -128,7 +165,7 @@ func LoadConfig() (*Config, error) {
|
||||
|
||||
// Bind environment variables
|
||||
v.AutomaticEnv()
|
||||
v.SetEnvPrefix("DLC") // DanceLessonsCoach prefix
|
||||
v.SetEnvPrefix("DLC") // dance-lessons-coach prefix
|
||||
v.BindEnv("server.host", "DLC_SERVER_HOST")
|
||||
v.BindEnv("server.port", "DLC_SERVER_PORT")
|
||||
v.BindEnv("shutdown.timeout", "DLC_SHUTDOWN_TIMEOUT")
|
||||
@@ -141,12 +178,24 @@ func LoadConfig() (*Config, error) {
|
||||
v.BindEnv("telemetry.otlp_endpoint", "DLC_TELEMETRY_OTLP_ENDPOINT")
|
||||
v.BindEnv("telemetry.service_name", "DLC_TELEMETRY_SERVICE_NAME")
|
||||
v.BindEnv("telemetry.insecure", "DLC_TELEMETRY_INSECURE")
|
||||
|
||||
// Auth environment variables
|
||||
v.BindEnv("auth.jwt_secret", "DLC_AUTH_JWT_SECRET")
|
||||
v.BindEnv("auth.admin_master_password", "DLC_AUTH_ADMIN_MASTER_PASSWORD")
|
||||
v.BindEnv("telemetry.sampler.type", "DLC_TELEMETRY_SAMPLER_TYPE")
|
||||
v.BindEnv("telemetry.sampler.ratio", "DLC_TELEMETRY_SAMPLER_RATIO")
|
||||
|
||||
// API environment variables
|
||||
v.BindEnv("api.v2_enabled", "DLC_API_V2_ENABLED")
|
||||
|
||||
// Database environment variables
|
||||
v.BindEnv("database.host", "DLC_DATABASE_HOST")
|
||||
v.BindEnv("database.port", "DLC_DATABASE_PORT")
|
||||
v.BindEnv("database.user", "DLC_DATABASE_USER")
|
||||
v.BindEnv("database.password", "DLC_DATABASE_PASSWORD")
|
||||
v.BindEnv("database.name", "DLC_DATABASE_NAME")
|
||||
v.BindEnv("database.ssl_mode", "DLC_DATABASE_SSL_MODE")
|
||||
|
||||
// Unmarshal into Config struct
|
||||
var config Config
|
||||
if err := v.Unmarshal(&config); err != nil {
|
||||
@@ -200,6 +249,11 @@ func (c *Config) GetServiceName() string {
|
||||
return c.Telemetry.ServiceName
|
||||
}
|
||||
|
||||
// GetPersistenceTelemetryEnabled returns whether persistence layer telemetry is enabled
|
||||
func (c *Config) GetPersistenceTelemetryEnabled() bool {
|
||||
return c.Telemetry.Enabled && c.Telemetry.Persistence.Enabled
|
||||
}
|
||||
|
||||
// GetTelemetryInsecure returns whether to use insecure connection
|
||||
func (c *Config) GetTelemetryInsecure() bool {
|
||||
return c.Telemetry.Insecure
|
||||
@@ -220,6 +274,21 @@ func (c *Config) GetV2Enabled() bool {
|
||||
return c.API.V2Enabled
|
||||
}
|
||||
|
||||
// GetJWTSecret returns the JWT secret
|
||||
func (c *Config) GetJWTSecret() string {
|
||||
return c.Auth.JWTSecret
|
||||
}
|
||||
|
||||
// GetAdminMasterPassword returns the admin master password
|
||||
func (c *Config) GetAdminMasterPassword() string {
|
||||
return c.Auth.AdminMasterPassword
|
||||
}
|
||||
|
||||
// GetLoggingJSON returns whether JSON logging is enabled
|
||||
func (c *Config) GetLoggingJSON() bool {
|
||||
return c.Logging.JSON
|
||||
}
|
||||
|
||||
// GetLogLevel returns the logging level
|
||||
func (c *Config) GetLogLevel() string {
|
||||
return c.Logging.Level
|
||||
@@ -230,6 +299,75 @@ func (c *Config) GetLogOutput() string {
|
||||
return c.Logging.Output
|
||||
}
|
||||
|
||||
// GetDatabaseHost returns the database host
|
||||
func (c *Config) GetDatabaseHost() string {
|
||||
if c.Database.Host == "" {
|
||||
return "localhost"
|
||||
}
|
||||
return c.Database.Host
|
||||
}
|
||||
|
||||
// GetDatabasePort returns the database port
|
||||
func (c *Config) GetDatabasePort() int {
|
||||
if c.Database.Port == 0 {
|
||||
return 5432
|
||||
}
|
||||
return c.Database.Port
|
||||
}
|
||||
|
||||
// GetDatabaseUser returns the database user
|
||||
func (c *Config) GetDatabaseUser() string {
|
||||
if c.Database.User == "" {
|
||||
return "postgres"
|
||||
}
|
||||
return c.Database.User
|
||||
}
|
||||
|
||||
// GetDatabasePassword returns the database password
|
||||
func (c *Config) GetDatabasePassword() string {
|
||||
return c.Database.Password
|
||||
}
|
||||
|
||||
// GetDatabaseName returns the database name
|
||||
func (c *Config) GetDatabaseName() string {
|
||||
if c.Database.Name == "" {
|
||||
return "dance_lessons_coach"
|
||||
}
|
||||
return c.Database.Name
|
||||
}
|
||||
|
||||
// GetDatabaseSSLMode returns the database SSL mode
|
||||
func (c *Config) GetDatabaseSSLMode() string {
|
||||
if c.Database.SSLMode == "" {
|
||||
return "disable"
|
||||
}
|
||||
return c.Database.SSLMode
|
||||
}
|
||||
|
||||
// GetDatabaseMaxOpenConns returns the maximum number of open connections
|
||||
func (c *Config) GetDatabaseMaxOpenConns() int {
|
||||
if c.Database.MaxOpenConns == 0 {
|
||||
return 25
|
||||
}
|
||||
return c.Database.MaxOpenConns
|
||||
}
|
||||
|
||||
// GetDatabaseMaxIdleConns returns the maximum number of idle connections
|
||||
func (c *Config) GetDatabaseMaxIdleConns() int {
|
||||
if c.Database.MaxIdleConns == 0 {
|
||||
return 5
|
||||
}
|
||||
return c.Database.MaxIdleConns
|
||||
}
|
||||
|
||||
// GetDatabaseConnMaxLifetime returns the maximum lifetime of connections
|
||||
func (c *Config) GetDatabaseConnMaxLifetime() time.Duration {
|
||||
if c.Database.ConnMaxLifetime == 0 {
|
||||
return time.Hour
|
||||
}
|
||||
return c.Database.ConnMaxLifetime
|
||||
}
|
||||
|
||||
// SetupLogging configures zerolog based on the configuration
|
||||
func (c *Config) SetupLogging() {
|
||||
// Parse log level
|
||||
|
||||
Reference in New Issue
Block a user