zdravko/pkg/k6/env.go
2024-02-21 14:09:22 +01:00

22 lines
551 B
Go

package k6
import "strings"
// ParseEnvKeyValue splits an environment variable string into key and value.
func ParseEnvKeyValue(kv string) (string, string) {
if idx := strings.IndexRune(kv, '='); idx != -1 {
return kv[:idx], kv[idx+1:]
}
return kv, ""
}
// BuildEnvMap returns a map from raw environment values, such as returned from
// os.Environ().
func BuildEnvMap(environ []string) map[string]string {
env := make(map[string]string, len(environ))
for _, kv := range environ {
k, v := ParseEnvKeyValue(kv)
env[k] = v
}
return env
}