1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 14:51:57 +00:00

Some util methods for kv style string

This commit is contained in:
Darren Shepherd
2018-09-24 08:59:45 -07:00
parent e93f1d7870
commit f06b9944e7

24
pkg/kv/split.go Normal file
View File

@@ -0,0 +1,24 @@
package kv
import "strings"
func Split(s, sep string) (string, string) {
parts := strings.SplitN(s, sep, 2)
return strings.TrimSpace(parts[0]), strings.TrimSpace(safeIndex(parts, 1))
}
func SplitMap(s, sep string) map[string]string {
result := map[string]string{}
for _, part := range strings.Split(s, sep) {
k, v := Split(part, "=")
result[k] = v
}
return result
}
func safeIndex(parts []string, idx int) string {
if len(parts) <= idx {
return ""
}
return parts[idx]
}