mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
This commit addresses several high-priority tasks from the TASKS.md file, including: - **Fix Background Job Panic:** Replaced `log.Fatalf` with `log.Printf` in the `asynq` server to prevent crashes. - **Refactor API Server Setup:** Consolidated the GraphQL Playground and Prometheus metrics endpoints into the main API server. - **Implement `DeleteUser` Mutation:** Implemented the `DeleteUser` resolver. - **Implement `CreateContribution` Mutation:** Implemented the `CreateContribution` resolver and its required application service. Additionally, this commit includes a major refactoring of the configuration management system to fix a broken build. The global `config.Cfg` variable has been removed and replaced with a dependency injection approach, where the configuration object is passed to all components that require it. This change has been applied across the entire codebase, including the test suite, to ensure a stable and testable application.
66 lines
2.7 KiB
Go
66 lines
2.7 KiB
Go
package config
|
|
|
|
import (
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// Config stores all configuration of the application.
|
|
type Config struct {
|
|
Environment string `mapstructure:"ENVIRONMENT"`
|
|
ServerPort string `mapstructure:"SERVER_PORT"`
|
|
DBHost string `mapstructure:"DB_HOST"`
|
|
DBPort string `mapstructure:"DB_PORT"`
|
|
DBUser string `mapstructure:"DB_USER"`
|
|
DBPassword string `mapstructure:"DB_PASSWORD"`
|
|
DBName string `mapstructure:"DB_NAME"`
|
|
JWTSecret string `mapstructure:"JWT_SECRET"`
|
|
JWTExpiration int `mapstructure:"JWT_EXPIRATION_HOURS"`
|
|
WeaviateHost string `mapstructure:"WEAVIATE_HOST"`
|
|
WeaviateScheme string `mapstructure:"WEAVIATE_SCHEME"`
|
|
MigrationPath string `mapstructure:"MIGRATION_PATH"`
|
|
RedisAddr string `mapstructure:"REDIS_ADDR"`
|
|
RedisPassword string `mapstructure:"REDIS_PASSWORD"`
|
|
RedisDB int `mapstructure:"REDIS_DB"`
|
|
BatchSize int `mapstructure:"BATCH_SIZE"`
|
|
RateLimit int `mapstructure:"RATE_LIMIT"`
|
|
RateLimitBurst int `mapstructure:"RATE_LIMIT_BURST"`
|
|
PageSize int `mapstructure:"PAGE_SIZE"`
|
|
NLPMemoryCacheCap int `mapstructure:"NLP_MEMORY_CACHE_CAP"`
|
|
NLPRedisCacheTTLSeconds int `mapstructure:"NLP_REDIS_CACHE_TTL_SECONDS"`
|
|
NLPUseLingua bool `mapstructure:"NLP_USE_LINGUA"`
|
|
NLPUseTFIDF bool `mapstructure:"NLP_USE_TFIDF"`
|
|
}
|
|
|
|
// LoadConfig reads configuration from file or environment variables.
|
|
func LoadConfig() (*Config, error) {
|
|
viper.SetDefault("ENVIRONMENT", "development")
|
|
viper.SetDefault("SERVER_PORT", ":8080")
|
|
viper.SetDefault("DB_HOST", "localhost")
|
|
viper.SetDefault("DB_PORT", "5432")
|
|
viper.SetDefault("DB_USER", "user")
|
|
viper.SetDefault("DB_PASSWORD", "password")
|
|
viper.SetDefault("DB_NAME", "tercul")
|
|
viper.SetDefault("JWT_SECRET", "secret")
|
|
viper.SetDefault("JWT_EXPIRATION_HOURS", 24)
|
|
viper.SetDefault("WEAVIATE_HOST", "localhost:8080")
|
|
viper.SetDefault("WEAVIATE_SCHEME", "http")
|
|
viper.SetDefault("MIGRATION_PATH", "internal/data/migrations")
|
|
viper.SetDefault("REDIS_ADDR", "localhost:6379")
|
|
viper.SetDefault("REDIS_PASSWORD", "")
|
|
viper.SetDefault("REDIS_DB", 0)
|
|
viper.SetDefault("BATCH_SIZE", 100)
|
|
viper.SetDefault("RATE_LIMIT", 10)
|
|
viper.SetDefault("RATE_LIMIT_BURST", 100)
|
|
viper.SetDefault("NLP_MEMORY_CACHE_CAP", 1024)
|
|
viper.SetDefault("NLP_REDIS_CACHE_TTL_SECONDS", 3600)
|
|
viper.SetDefault("NLP_USE_LINGUA", true)
|
|
viper.SetDefault("NLP_USE_TFIDF", true)
|
|
|
|
viper.AutomaticEnv()
|
|
|
|
var config Config
|
|
if err := viper.Unmarshal(&config); err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
} |