Files
grafana/pkg/util/shortid_generator.go
T

32 lines
676 B
Go
Raw Normal View History

package util
import (
2018-02-15 09:56:13 +01:00
"regexp"
"github.com/teris-io/shortid"
)
2018-02-15 09:56:13 +01:00
var allowedChars = shortid.DefaultABC
var validUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
2018-02-15 09:56:13 +01:00
2018-02-15 14:56:52 +01:00
func init() {
gen, _ := shortid.New(1, allowedChars, 1)
shortid.SetDefault(gen)
}
// IsValidShortUID checks if short unique identifier contains valid characters
func IsValidShortUID(uid string) bool {
return validUIDPattern(uid)
2018-02-15 09:56:13 +01:00
}
// IsShortUIDTooLong checks if short unique identifier is too long
func IsShortUIDTooLong(uid string) bool {
return len(uid) > 40
}
// GenerateShortUID generates a short unique identifier.
func GenerateShortUID() string {
return shortid.MustGenerate()
}