Packages

config

Load environment variables from .env files into typed structs. Validates required fields on load so your app fails fast with a clear error.


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
}

// Postgres.DSN is built automatically from individual fields:
// "host=... port=... user=... password=... dbname=... sslmode=..."

.env.example

APP_NAME=myapp
APP_PORT=8080
APP_ENV=development

DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=mydb
DB_SSLMODE=disable

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

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

JWT_SECRET=change-me-in-production

JWT_SECRET must not be empty — config.Load() returns an error if it is.