env

package module
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

Package Env

A flexible environment variable loader for Go 1.25+ that supports variable expansion, inline comments, and strong typing.

Features

  • Variable Expansion: Use ${VAR} syntax to compose variables from others.
  • Strong Typing: Automatically convert strings to int, bool, time.Time, Duration, and json.RawMessage.
  • Clean Parsing: Supports spaces around =, export prefix, and # or // comments.
  • Default Values: Provide fallbacks easily via generics.

Usage

1. Create a .env file
DB_HOST     = localhost
DB_USER     = admin
DB_URL      = "postgres://${DB_USER}@${DB_HOST}:5432/db"
DEBUG       = true
TIMEOUT     = 5s
2. Load and Access
env.Load(".env")

url := env.Get[string]("DB_URL")
debug := env.Get[bool]("DEBUG", false)
timeout := env.Get[time.Duration]("TIMEOUT")

Installation

go get github.com/leandroluk/gox/env

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](key string, optionalDefault ...T) T

Get retrieves an environment variable and converts it to T. Returns default value if not found or conversion fails.

func Load

func Load(filePaths ...string)

Load reads the first valid .env file from the provided paths.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL