PairsToMap creates a map from a slice of "key=value" environment variable pairs. Note that maps are not ordered, which can affect the final variable values when pairs contains duplicate keys.
(pairs []string)
| 63 | // pairs. Note that maps are not ordered, which can affect the final variable |
| 64 | // values when pairs contains duplicate keys. |
| 65 | func PairsToMap(pairs []string) map[string]string { |
| 66 | vars := make(map[string]string, len(pairs)) |
| 67 | for _, p := range pairs { |
| 68 | k, v, ok := strings.Cut(p, "=") |
| 69 | if !ok { |
| 70 | continue |
| 71 | } |
| 72 | vars[k] = v |
| 73 | } |
| 74 | return vars |
| 75 | } |
no outgoing calls