1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/github.com/shurcooL/go/osutil/environ.go
2017-10-03 14:43:55 -04:00

31 lines
753 B
Go

// Package osutil offers a utility for manipulating a set of environment variables.
package osutil
import "strings"
// Environ is a slice of strings representing the environment, in the form "key=value".
type Environ []string
// Set environment variable key to value.
func (e *Environ) Set(key, value string) {
for i := range *e {
if strings.HasPrefix((*e)[i], key+"=") {
(*e)[i] = key + "=" + value
return
}
}
// If we get here, it's because the key isn't already present, so add a new one.
*e = append(*e, key+"="+value)
}
// Unset environment variable key.
func (e *Environ) Unset(key string) {
for i := range *e {
if strings.HasPrefix((*e)[i], key+"=") {
(*e)[i] = (*e)[len(*e)-1]
*e = (*e)[:len(*e)-1]
return
}
}
}