Update dependenciess

Exclude minio-go for now (pin to 3.x.y).
This commit is contained in:
Alexander Neumann
2017-12-03 21:01:25 +01:00
parent 9d0f13c4c0
commit 946c8399e2
2985 changed files with 1008107 additions and 118934 deletions

View File

@@ -31,17 +31,24 @@ var startTime = time.Now().UTC()
// A UIDSpace manages a set of unique IDs distinguished by a prefix.
type UIDSpace struct {
Prefix string
Sep rune
re *regexp.Regexp
mu sync.Mutex
count int
}
func NewUIDSpace(prefix string) *UIDSpace {
return NewUIDSpaceSep(prefix, '-')
}
func NewUIDSpaceSep(prefix string, sep rune) *UIDSpace {
re := fmt.Sprintf(`^%s%[2]c(\d{4})(\d{2})(\d{2})%[2]c(\d+)%[2]c\d+$`,
regexp.QuoteMeta(prefix), sep)
return &UIDSpace{
Prefix: prefix,
re: regexp.MustCompile("^" + regexp.QuoteMeta(prefix) + `-(\d{4})(\d{2})(\d{2})-(\d+)-\d+$`),
Sep: sep,
re: regexp.MustCompile(re),
}
}
// New generates a new unique ID . The ID consists of the UIDSpace's prefix, a
@@ -49,7 +56,7 @@ func NewUIDSpace(prefix string) *UIDSpace {
// execution will have the same timestamp.
//
// Aside from the characters in the prefix, IDs contain only letters, numbers
// and hyphens.
// and sep.
func (s *UIDSpace) New() string { return s.newID(startTime) }
func (s *UIDSpace) newID(t time.Time) string {
@@ -62,7 +69,8 @@ func (s *UIDSpace) newID(t time.Time) string {
y, m, d := t.Date()
ns := t.Sub(time.Date(y, m, d, 0, 0, 0, 0, time.UTC))
// Zero-pad the counter for lexical sort order for IDs with the same timestamp.
return fmt.Sprintf("%s-%04d%02d%02d-%d-%04d", s.Prefix, y, m, d, ns, c)
return fmt.Sprintf("%s%c%04d%02d%02d%c%d%c%04d",
s.Prefix, s.Sep, y, m, d, s.Sep, ns, s.Sep, c)
}
// Timestamp extracts the timestamp of uid, which must have been generated by

View File

@@ -27,6 +27,13 @@ func TestNew(t *testing.T) {
if got != want {
t.Errorf("got %q, want %q", got, want)
}
s2 := NewUIDSpaceSep("prefix2", '_')
got = s2.newID(tm)
want = "prefix2_20170106_21_0000"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
func TestTimestamp(t *testing.T) {