-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
39 lines (34 loc) · 932 Bytes
/
utils.go
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
35
36
37
38
39
package authorizer
import (
"encoding/base64"
"math/rand"
)
// CreateRandomString returns a random string 43 characters
func CreateRandomString() string {
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, 43)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
// EncodeB64 returns string which is base64 encoded
func EncodeB64(message string) string {
base64Text := make([]byte, base64.StdEncoding.EncodedLen(len(message)))
base64.StdEncoding.Encode(base64Text, []byte(message))
return string(base64Text)
}
// NewStringRef returns a reference to a string with given value
func NewStringRef(v string) *string {
return &v
}
// StringValue returns the value of the given string ref
func StringValue(r *string, defaultValue ...string) string {
if r != nil {
return *r
}
if len(defaultValue) > 0 {
return defaultValue[0]
}
return ""
}