Files

31 lines
497 B
Go
Raw Permalink Normal View History

package helpers
import (
"crypto/rand"
"encoding/hex"
"strings"
)
func RandomHexID(byteCount int) (string, error) {
bytes := make([]byte, byteCount)
if _, err := rand.Read(bytes); err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil
}
func ValidLowerHexID(value string, length int) bool {
if len(value) != length {
return false
}
for _, character := range value {
if !strings.ContainsRune("0123456789abcdef", character) {
return false
}
}
return true
}