⚙️ config – Environment Configuration Loader

The config package uses Viper to load application settings from .env files and environment variables. It centralizes important runtime configuration like database URLs, server addresses, and secret keys.


🧩 Core Types

Config

type Config struct {
	DBSource            string
	ServerAddress       string
	TokenSymmetricKey   string
	AccessTokenDuration time.Duration
	GeminiAPIKey        string
}

Represents application-wide configuration values loaded from an environment file.


LoadConfig

func LoadConfig(path string) (Config, error)

Loads config values from a file named app.env located in the given directory path. Uses viper to also pull values from environment variables.

🧠 Logic

  1. Looks for app.env in the specified path.
  2. Parses key-value pairs using Viper.
  3. Maps them into a typed Config struct.
  4. Returns the struct for use across the application.

📄 Example app.env file

DB_SOURCE=postgres://user:pass@localhost:5432/dbname
SERVER_ADDRESS=0.0.0.0:8080
TOKEN_SYMMETRIC_KEY=supersecretkey1234567890123456
ACCESS_TOKEN_DURATION=15m
GEMINI_API_KEY=your-gemini-api-key-here