forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uuid.go
33 lines (26 loc) · 816 Bytes
/
uuid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package uuid
import (
"regexp"
"strings"
"github.com/satori/go.uuid"
)
// New returns a new uuid.
func New() string {
return uuid.NewV4().String()
}
// NewWithoutDashes returns a new uuid without no "-".
func NewWithoutDashes() string {
return strings.Replace(New(), "-", "", -1)
}
// NewWithoutUnderscores returns a new uuid without no "_".
func NewWithoutUnderscores() string {
return strings.Replace(New(), "_", "", -1)
}
// IsUUIDWithoutDashes checks whether a string is a UUID without dashes
func IsUUIDWithoutDashes(s string) bool {
return uuidWithoutDashesRegexp.MatchString(s)
}
// Because we use UUIDv4, the 13th character is a '4'.
// Moreover, a UUID can only contain "hexadecimal" characters,
// lowercase here.
var uuidWithoutDashesRegexp = regexp.MustCompile("[0-9a-f]{12}4[0-9a-f]{19}")