env

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package env provides typed helpers for reading configuration from environment variables with defaults. An unset or empty variable — or one that fails to parse — yields the provided default.

Example

Each reader takes the default inline, so configuration reads as one expression rather than a lookup followed by a zero-value check.

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/dobrevit/svckit/env"
)

func main() {
	os.Setenv("PORT", "9000")
	os.Setenv("FEATURE_ENABLED", "true")
	defer func() {
		os.Unsetenv("PORT")
		os.Unsetenv("FEATURE_ENABLED")
	}()

	fmt.Println(env.String("PORT", "8080"))
	fmt.Println(env.Bool("FEATURE_ENABLED", false))
	fmt.Println(env.Duration("SHUTDOWN_GRACE", 30*time.Second))
}
Output:
9000
true
30s

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string, def bool) bool

Bool returns the variable parsed as a bool ("1", "t", "true", "0", "false", ...), or def when unset or unparsable.

func Duration

func Duration(key string, def time.Duration) time.Duration

Duration returns the variable parsed with time.ParseDuration ("30s", "5m"), or def when unset or unparsable.

func Int

func Int(key string, def int) int

Int returns the variable parsed as an int, or def when unset or unparsable.

func Int64

func Int64(key string, def int64) int64

Int64 returns the variable parsed as an int64, or def when unset or unparsable.

func Slice

func Slice(key string, def []string) []string

Slice returns the variable split on commas with whitespace trimmed and empty items dropped, or def when unset or empty.

func String

func String(key, def string) string

String returns the value of the environment variable, or def when unset or empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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