Refactor configuration management by migrating to a modular config system
- Removed the old `infra.Config` structure and replaced it with a new modular configuration system in `pkg/config`. - Introduced a `Config` struct in `cmd/web/config.go` to hold command-specific configurations. - Updated configuration loading functions to utilize the new `LoadConfig` method with generics for type safety. - Adjusted various initialization functions in `cmd/web/bootstrap.go` and `cmd/web/main.go` to reflect the new configuration structure. - Cleaned up the `config.yaml` by removing obsolete fields and ensuring it aligns with the new configuration schema.
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
"tm/infra"
|
||||
"tm/pkg/authorization"
|
||||
"tm/pkg/config"
|
||||
"tm/pkg/logger"
|
||||
"tm/pkg/mongo"
|
||||
"tm/pkg/redis"
|
||||
@@ -16,17 +16,17 @@ import (
|
||||
)
|
||||
|
||||
// Init Application Configuration
|
||||
func initConfig() infra.Config {
|
||||
config, err := infra.LoadConfig(".")
|
||||
func initConfig() Config {
|
||||
conf, err := config.LoadConfig(".", &Config{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to load config: %v", err))
|
||||
}
|
||||
|
||||
return *config
|
||||
return *conf
|
||||
}
|
||||
|
||||
// Init Logger Service
|
||||
func initLogger(conf infra.LoggingConfig) logger.Logger {
|
||||
func initLogger(conf config.LoggingConfig) logger.Logger {
|
||||
return logger.NewLogger(&logger.Config{
|
||||
Level: conf.Level,
|
||||
Format: conf.Format,
|
||||
@@ -42,7 +42,7 @@ func initLogger(conf infra.LoggingConfig) logger.Logger {
|
||||
}
|
||||
|
||||
// Init MongoDB Connection Manager
|
||||
func initMongoDB(conf infra.MongoConfig, log logger.Logger) *mongo.ConnectionManager {
|
||||
func initMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionManager {
|
||||
// Convert infra.MongoConfig to mongo.ConnectionConfig
|
||||
connectionConfig := mongo.ConnectionConfig{
|
||||
URI: conf.URI,
|
||||
@@ -75,7 +75,7 @@ func initMongoDB(conf infra.MongoConfig, log logger.Logger) *mongo.ConnectionMan
|
||||
}
|
||||
|
||||
// initHTTPServer initializes the Echo HTTP server with middleware
|
||||
func initHTTPServer(conf infra.Config, log logger.Logger) *echo.Echo {
|
||||
func initHTTPServer(conf Config, log logger.Logger) *echo.Echo {
|
||||
e := echo.New()
|
||||
|
||||
// Configure Echo
|
||||
@@ -129,7 +129,7 @@ func initHTTPServer(conf infra.Config, log logger.Logger) *echo.Echo {
|
||||
}
|
||||
|
||||
// Init Redis Connection Manager
|
||||
func initRedis(conf infra.RedisConfig, log logger.Logger) redis.Client {
|
||||
func initRedis(conf config.RedisConfig, log logger.Logger) redis.Client {
|
||||
connectionConfig := &redis.Config{
|
||||
Host: conf.Host,
|
||||
Port: conf.Port,
|
||||
@@ -158,7 +158,7 @@ func initRedis(conf infra.RedisConfig, log logger.Logger) redis.Client {
|
||||
}
|
||||
|
||||
// Init Authorization Service
|
||||
func initAuthorizationService(conf infra.JWTConfig, redisClient redis.Client, log logger.Logger) authorization.AuthorizationService {
|
||||
func initAuthorizationService(conf JWTConfig, redisClient redis.Client, log logger.Logger) authorization.AuthorizationService {
|
||||
authConfig := &authorization.AuthorizationConfig{
|
||||
AccessTokenSecret: conf.AccessSecret,
|
||||
RefreshTokenSecret: conf.RefreshSecret,
|
||||
|
||||
Reference in New Issue
Block a user