mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-01 02:59:24 +02:00
Make simple actions parsing work
This commit is contained in:
parent
55869f551e
commit
5a9b2122c2
7 changed files with 160 additions and 21 deletions
util
10
util/util.go
10
util/util.go
|
@ -77,6 +77,16 @@ func SplitNoEmpty(s string, sep string) []string {
|
|||
return res
|
||||
}
|
||||
|
||||
// SplitKV splits a string into a key/value pair using a separator, and trimming space. If the separator
|
||||
// is not found, key is empty.
|
||||
func SplitKV(s string, sep string) (key string, value string) {
|
||||
kv := strings.SplitN(strings.TrimSpace(s), sep, 2)
|
||||
if len(kv) == 2 {
|
||||
return strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])
|
||||
}
|
||||
return "", strings.TrimSpace(kv[0])
|
||||
}
|
||||
|
||||
// RandomString returns a random string with a given length
|
||||
func RandomString(length int) string {
|
||||
randomMutex.Lock() // Who would have thought that random.Intn() is not thread-safe?!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue