Skip to content

Commit

Permalink
feat(envx): add to env func
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jan 11, 2025
1 parent 8fd5e5d commit d09b973
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions envx/env.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package envx

import (
"strings"
)

// Env is the environment variables.
type Env map[string]string

Expand All @@ -23,3 +27,19 @@ func (e Env) Strings() []string {

return result
}

// ToEnv converts the environment to a list of strings.
func ToEnv(env []string) Env {
ee := Env{}

for _, e := range env {
k, v, ok := strings.Cut(e, "=")
if !ok || k == "" {
continue
}

ee[k] = v
}

return ee
}

0 comments on commit d09b973

Please sign in to comment.