-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We need these to be accessible from cmd/state as well.
- Loading branch information
Ivan Mirić
committed
Jan 13, 2023
1 parent
a0df81c
commit bb6fac1
Showing
3 changed files
with
23 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package lib | ||
|
||
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 | ||
} |