Skip to content

Refactor: replace global config.C with idiomatic getter #3

@joelfokou

Description

@joelfokou

Problem

The current implementation uses a global exported variable var C Config. This can cause a few issues

  • The global variable can be overwritten by any package importing config.
  • Doesn't respect naming clarity according to "Effective Go" principles.
  • config.C is often mistaken for CGo calls.

Proposed Solution

Refactor the config package to hide the global state and expose it through a read-only getter.

Changes in config/config.go

  • Change var C Config to var instance Config.
  • Implement a Get() function.
func Get() Config {
    return instance
}
  • Ensure Load() populates the unexported instance and returns (*Config, error) for better accessibility throughout project.

Project-wide Impact

Replace all instances of config.C with config.Get().

Current Refactored
config.C.LogLevel config.Get().LogLevel
config.C.Paths.Database config.Get().Paths.Database

Definition of Done

  • config.C is no longer exported.
  • No direct modification of configuration is possible from external packages.
  • All existing tests run successfully go test ./....
  • Application compiles successfully with config.Get().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions