github.com/msales/pkg/v3@v3.24.0/utils/strings.go (about) 1 package utils 2 3 import "strings" 4 5 // SplitMap splits a slice of strings into a map of strings using 6 // the given separator. 7 func SplitMap(s []string, sep string) map[string]string { 8 if len(s) == 0 || sep == "" { 9 return nil 10 } 11 m := make(map[string]string) 12 for _, str := range s { 13 parts := strings.SplitN(str, sep, 2) 14 v := "" 15 if len(parts) > 1 { 16 v = parts[1] 17 } 18 m[parts[0]] = v 19 } 20 return m 21 }