okami.mom/ultraviolet
git clone https://git.nkp.pet/okami.mom/ultraviolet
b3a6f4b
main
1package uv 2 3import ( 4"strings" 5) 6 7// Environ is a slice of strings that represents the environment variables of 8// the program. 9type Environ []string 10 11// Getenv returns the value of the environment variable named by the key. If 12// the variable is not present in the environment, the value returned will be 13// the empty string. 14func (p Environ )Getenv (key string ) (v string ) { 15v ,_ = p .LookupEnv (key ) 16return 17} 18 19// LookupEnv retrieves the value of the environment variable named by the key. 20// If the variable is present in the environment the value (which may be empty) 21// is returned and the boolean is true. Otherwise the returned value will be 22// empty and the boolean will be false. 23func (p Environ )LookupEnv (key string ) (s string ,v bool ) { 24for i := len (p )- 1 ;i >= 0 ;i -- { 25if strings .HasPrefix (p [i ],key + "=" ) { 26s = strings .TrimPrefix (p [i ],key + "=" ) 27v = true 28break 29 } 30 } 31return 32}