env

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

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

Jump to

Keyboard shortcuts

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