Add id generator based on time

pull/2617/head
Chris Goller 2017-12-14 22:43:50 -06:00 committed by Michael Desa
parent e23defe7a6
commit b54ed7705c
1 changed files with 25 additions and 0 deletions

25
id/time.go Normal file
View File

@ -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
}