env

package
v12.124.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 8

Documentation

Overview

Package env provides methods for working with environment variables

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Which

func Which(name string) string

Which find full path to some app

Example
echoPath := Which("echo")

fmt.Printf("Full path to echo binary is %s\n", echoPath)
Output:

Types

type Env

type Env map[string]string

Env is map with environment values

func Get

func Get() Env

Get return key-value map with environment values

Example
env := Get()

// Print PATH environment variable
fmt.Println(env["PATH"])

// Path return PATH variable as slice
for i, p := range env.Path() {
	fmt.Printf("%d %s\n", i, p)
}

// You can use getters for different value formats
fmt.Printf("Integer value %s = %d\n", "INT_VALUE", env.GetI("INT_VALUE"))
fmt.Printf("Float value %s = %g\n", "FLOAT_VALUE", env.GetF("FLOAT_VALUE"))
fmt.Printf("String value %s = %s\n", "STR_VALUE", env.GetS("STR_VALUE"))
Output:

func (Env) GetF

func (e Env) GetF(name string) float64

GetF return environment variable value as float

func (Env) GetI

func (e Env) GetI(name string) int

GetI return environment variable value as int

func (Env) GetS

func (e Env) GetS(name string) string

GetS return environment variable value as string

func (Env) Path

func (e Env) Path() []string

Path return path as string slice

type Variable added in v12.124.0

type Variable struct {
	// contains filtered or unexported fields
}

Variable is environment variable for lazy reading

func Var added in v12.124.0

func Var(name string) *Variable

Var creates new environment variable struct

Example
v := Var("PATH")

fmt.Println(v.Get())
Output:

func (*Variable) Get added in v12.124.0

func (v *Variable) Get() string

Get returns environment variable value

func (*Variable) Is added in v12.124.0

func (v *Variable) Is(value string) bool

Is returns true if environment variable value is equal to given one

func (*Variable) Reset added in v12.124.0

func (v *Variable) Reset() *Variable

Reset resets reading state of variable

func (*Variable) String added in v12.124.0

func (v *Variable) String() string

String returns environment variable value as string

Jump to

Keyboard shortcuts

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