This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
summer-utils/utils/key-value-string.go

25 lines
456 B
Go

package utils
import "strings"
type KeyValuePair struct{ key, value string }
func ParseKeyValueString(text string) *KeyValuePair {
v := strings.SplitN(text, "=", 2)
if len(v) != 2 {
return nil
}
return &KeyValuePair{v[0], v[1]}
}
func ParseKeyValueFromStringArray(text []string) []KeyValuePair {
out := make([]KeyValuePair, 0)
for _, a := range text {
b := ParseKeyValueString(a)
if b != nil {
out = append(out, *b)
}
}
return out
}