-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhelpers.go
More file actions
34 lines (28 loc) · 750 Bytes
/
helpers.go
File metadata and controls
34 lines (28 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package ussd
import (
"fmt"
"log"
"math/rand"
"strings"
)
var alphaNumeric = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
// StrLower returns lowercase s.
func StrLower(s string) string {
return strings.ToLower(s)
}
// StrTrim returns s with excess whitespace removed.
func StrTrim(s string) string {
return strings.TrimSpace(s)
}
// StrRandom returns random string of given length.
func StrRandom(length int) string {
result := make([]rune, length)
for i := range result {
result[i] = alphaNumeric[rand.Intn(len(alphaNumeric))]
}
return string(result)
}
// panicln takes formatted string and panics with an error.
func panicln(format string, a ...interface{}) {
log.Panicln(fmt.Errorf(format, a...))
}