Karma Config Package
Thekarma/config package helps you manage application configuration using .env files. It includes helpers for loading default configs, custom structs, and individual environment variables — all without hardcoding secrets.
Karma relies heavily on environment variables across all modules. Use this package to manage them effectively.
🔧 Setup
Installkarma:
.env file in your project root:
📦 Default Configuration
UseDefaultConfig() to load all predefined environment variables into a Config struct.
Config struct includes a comprehensive list of fields such as:
Port,JWTSecret,DatabaseURL,RedisURL, etc.- AWS, Twilio, Stripe, OpenAI, and Mailgun credentials
- Custom webhook and platform keys (
KARMAPAY_*)
🧩 Custom Struct Configuration
UseCustomConfig(cfg interface{}) if you only need a subset of variables or a custom struct layout.
Example
Each field must be tagged withenv:"VARIABLE_NAME". If theenvtag is missing, it defaults to the field name.
🔍 Get Individual Variables
Use these helpers when you want to fetch specific keys:GetEnv
.env fails to load.
GetEnvOrDefault
GetEnvRaw
🧪 Example .env Template
🧠 Pro Tips
- Always use
CustomConfig()for CLI tools or microservices with limited env requirements. - Store
.envat the root of your project and never commit it to version control. - Prefer
GetEnvOrDefault()when building tools or scripts that work in local/dev environments.