25 lines
456 B
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
|
||
|
}
|