Skip to content

Commit

Permalink
Add id generator based on time
Browse files Browse the repository at this point in the history
  • Loading branch information
goller authored and desa committed Dec 19, 2017
1 parent e23defe commit b54ed77
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions id/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package id

import (
"strconv"
"time"

"github.com/influxdata/chronograf"
)

// tm generates an id based on current time
type tm struct {
Now func() time.Time
}

// NewTime builds a chronograf.ID generator based on current time
func NewTime() chronograf.ID {
return &tm{
Now: time.Now,
}
}

// Generate creates a string based on the current time as an integer
func (i *tm) Generate() (string, error) {
return strconv.Itoa(int(i.Now().Unix())), nil
}

0 comments on commit b54ed77

Please sign in to comment.