Files
golib/env
..
2026-01-02 19:03:07 +11:00
2026-01-02 19:03:07 +11:00
2026-01-02 19:03:07 +11:00
2026-01-10 18:22:16 +11:00
2026-01-10 18:22:16 +11:00
2026-01-02 19:03:07 +11:00
2026-01-10 18:22:16 +11:00
2026-01-10 18:22:16 +11:00

env v1.0.0

Environment variable utilities for Go applications with type safety and default values.

Features

  • Type-safe environment variable parsing
  • Support for all basic Go types (string, int variants, uint variants, bool, time.Duration)
  • Graceful fallback to default values
  • Comprehensive boolean parsing with multiple truthy/falsy values
  • Full test coverage

Installation

go get git.haelnorr.com/h/golib/env

Quick Start

package main

import (
    "fmt"
    "time"
    "git.haelnorr.com/h/golib/env"
)

func main() {
    // String values
    host := env.String("HOST", "localhost")
    
    // Integer values (all sizes supported)
    port := env.Int("PORT", 8080)
    timeout := env.Int64("TIMEOUT_SECONDS", 30)
    
    // Unsigned integer values
    maxConnections := env.UInt("MAX_CONNECTIONS", 100)
    
    // Boolean values (supports many formats)
    debug := env.Bool("DEBUG", false)
    
    // Duration values
    requestTimeout := env.Duration("REQUEST_TIMEOUT", 30*time.Second)
    
    fmt.Printf("Server: %s:%d\n", host, port)
    fmt.Printf("Debug: %v\n", debug)
    fmt.Printf("Timeout: %v\n", requestTimeout)
}

Documentation

See the wiki documentation for detailed usage information and examples.

License

MIT License

Contributing

Please see the main golib repository for contributing guidelines.

This package is part of the golib collection of utilities for Go applications.