goenv

package module
v0.0.0-...-ce41afb Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 6 Imported by: 4

README

os.Getenv wrapper

Installation

go get -u github.com/allape/goenv

Example

package main

import (
	"fmt"
	"github.com/allape/goenv"
	"reflect"
)

type StringAlias string

func (s StringAlias) Print() {
	fmt.Println(s)
}

func main() {
	value, err := goenv.MustGetenv("ENV_VAR", 1)
	if err != nil {
		panic(err)
	}
	fmt.Println(value)                        // 1
	fmt.Println(reflect.TypeOf(value).Kind()) // int // see https://golang.org/pkg/reflect/#Kind for more information

	str, err := goenv.MustGetenv("ENV_VAR", StringAlias("string alias"))
	if err != nil {
		panic(err)
	}
	str.Print() // string alias
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnsupportedTypeError = errors.New("unsupported type")

Functions

func Getenv

func Getenv[T comparable](key string, defaultValue T) T

func MustGetenv

func MustGetenv[T comparable](key string, defaultValue T) (T, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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