From b54ed7705cce414f3a34c02570a1d1f86cd2eba6 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Thu, 14 Dec 2017 22:43:50 -0600 Subject: [PATCH] Add id generator based on time --- id/time.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 id/time.go diff --git a/id/time.go b/id/time.go new file mode 100644 index 000000000..75687c7c8 --- /dev/null +++ b/id/time.go @@ -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 +}