2023-04-02 22:50:22 +02:00
|
|
|
// Package common contains functions and types common to all (or most) packages.
|
|
|
|
package common
|
|
|
|
|
2023-12-18 23:39:16 +01:00
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/base64"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
2023-04-02 22:50:22 +02:00
|
|
|
|
|
|
|
func StringLength(s *string) int {
|
|
|
|
if s == nil {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return utf8.RuneCountInString(*s)
|
|
|
|
}
|
2023-12-18 23:39:16 +01:00
|
|
|
|
|
|
|
// RandBase64 returns a string of random bytes encoded in raw base 64.
|
|
|
|
func RandBase64(size int) string {
|
|
|
|
b := make([]byte, size)
|
|
|
|
_, err := rand.Read(b)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return base64.RawURLEncoding.EncodeToString(b)
|
|
|
|
}
|