Packages

config

Load environment variables from .env files into typed structs. Validates fields for enabled adapters so your app fails fast with a clear error — and stays quiet about infra you did not turn on.


Usage

import "github.com/BounkhongDev/bkgo/config"

// Reads .env by default
cfg, err := config.Load()

// Custom file(s)
cfg, err := config.Load(".env.prod")
cfg, err := config.Load(".env", ".env.local")

Config struct

type Config struct {
    App             App
    Postgres        Postgres
    Redis           Redis
    MinIO           MinIO
    JWT             JWT
    PostgresEnabled bool
    RedisEnabled    bool
    MinIOEnabled    bool
    JWTEnabled      bool
}

// Postgres.DSN is built automatically from individual fields.
// *_ENABLED flags only guide wiring in main — adapters stay strict.

Adapter flags

Use cfg.PostgresEnabled, cfg.RedisEnabled, cfg.MinIOEnabled, and cfg.JWTEnabled in cmd/api/main.go to construct adapters. Do not put adapter imports in usecases.


.env.example

APP_NAME=myapp
APP_PORT=8080
APP_ENV=development

DB_ENABLED=true
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=mydb
DB_SSL_MODE=disable

REDIS_ENABLED=false
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0

MINIO_ENABLED=false
MINIO_ENDPOINT=localhost:9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET=uploads
MINIO_USE_SSL=false

JWT_ENABLED=false
JWT_SECRET=

Defaults: DB_ENABLED=true; Redis / MinIO / JWT off. JWT_SECRET is required only when JWT is enabled (or when the flag is omitted and a secret is set — legacy).