pronounss/backend/common/common.go
2023-12-18 23:39:16 +01:00

26 lines
501 B
Go

// Package common contains functions and types common to all (or most) packages.
package common
import (
"crypto/rand"
"encoding/base64"
"unicode/utf8"
)
func StringLength(s *string) int {
if s == nil {
return -1
}
return utf8.RuneCountInString(*s)
}
// 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)
}