Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created July 3, 2012 14:08
Show Gist options
  • Save jgrahamc/3039932 to your computer and use it in GitHub Desktop.
Save jgrahamc/3039932 to your computer and use it in GitHub Desktop.
Counting ID generator
id := make(chan string)
count := make(chan int)
go func() {
h := sha1.New()
w := counter.New(h)
c := []byte(time.Now().String())
w.Write(c)
for {
select {
case id <- fmt.Sprintf("%x", h.Sum(nil)):
w.Write(c)
case count <- w.Count():
w.Clear()
}
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment