getenv

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 6 Imported by: 3

README

GetEnv

Go Reference Bitbucket Pipelines

Installation

go get bitbucket.org/amotus/getenv

Usage

package main

import (
	"time"

	"bitbucket.org/amotus/getenv"
)

func main() {
	s := getenv.String("VAR_STRING", "default")
	i := getenv.Int("VAR_INT", 0)
	i64 := getenv.Int64("VAR_INT64", int64(0))
	b := getenv.Bool("VAR_BOOL", false)
	t := getenv.TimeDuration("VAR_TIME", 60*time.Second)
	t := getenv.IntArray("VAR_INT_ARRAY", []int{})
	t := getenv.Int64Array("VAR_INT64_ARRAY", []int{})
	
	s2 := getenv.MustGetString("MANDATORY_STRING")
}

Please refer to the comments on these functions for detailed information

Releasing a new version

Please look at the most recent git tag, and choose a new value following the vMAJOR.MINOR.PATCH model. Use the custom pipeline 'Release version' with your new tag as version.

License

Licensed under Apache License, Version 2.0 LICENSE.

Documentation

Overview

Package getenv provide the implementation of a LookupEnv pattern with default value handling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string, defaultValue bool) bool

Bool returns the bool value of the environment variable named by the key, or defaultValue if the environment variable is not set. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns default value.

func Int

func Int(key string, defaultValue int) int

Int returns the int value of the environment variable named by the key, or defaultValue if the environment variable is not set.

func Int64

func Int64(key string, defaultValue int64) int64

Int64 returns the int64 value of the environment variable named by the key, or defaultValue if the environment variable is not set.

func Int64Array added in v0.0.6

func Int64Array(key string, defaultValue []int64) []int64

Int64Array returns an array of 64 bit integers from the environment variable by the key, or the default value if the environment variable is not set. It accepts any array of int64 value as long as the array is in a string "[56, 8, 1]" Brackets are optional and whitespace will be trimmed. Any other value returns default value.

func IntArray added in v0.0.2

func IntArray(key string, defaultValue []int) []int

IntArray returns an array of integers from the environment variable by the key, or the default value if the environment variable is not set. It accepts any array of int value as long as the array is in a string "[56, 8, 1]" Brackets are optional and whitespace will be trimmed. Any other value returns default value.

func MustGetString added in v0.0.5

func MustGetString(key string) string

MustGetString returns the string value of the environment variable named by the key, or panics if the environment variable is not set.

func String

func String(key string, defaultValue string) string

String returns the string value of the environment variable named by the key, or defaultValue if the environment variable is not set.

func TimeDuration

func TimeDuration(key string, defaultValue time.Duration) time.Duration

TimeDuration returns the time.Duration value of the environment variable named by the key, or defaultValue if the environment variable is not set. If the value is numeric, it assumes it is a nanosecond number. Otherwise, it parses it according to https://pkg.go.dev/time#ParseDuration

Types

This section is empty.

Jump to

Keyboard shortcuts

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