mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
da5654ad04
pkg/util/shortid_generator.go:20:2: should use 'return <expr>' instead of 'if <expr> { return <bool> }; return <bool>' (S1008)
27 lines
542 B
Go
27 lines
542 B
Go
package util
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/teris-io/shortid"
|
|
)
|
|
|
|
var allowedChars = shortid.DefaultABC
|
|
|
|
var validUidPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
|
|
|
|
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)
|
|
}
|
|
|
|
// GenerateShortUid generates a short unique identifier.
|
|
func GenerateShortUid() string {
|
|
return shortid.MustGenerate()
|
|
}
|