Skip to content

Instantly share code, notes, and snippets.

@momer
Created May 8, 2014 13:17
Show Gist options
  • Save momer/72bdb428b85ab4234dc3 to your computer and use it in GitHub Desktop.
Save momer/72bdb428b85ab4234dc3 to your computer and use it in GitHub Desktop.
Golang example of creating a timestamped key for an immutable key/value store like Groupcache.
package main
import "fmt"
import "time"
import "encoding/hex"
import "hash/fnv"
func main() {
h := fnv.New64a()
// Hash of Timestamp rounded to previous hour
h.Write([]byte(time.Now().Round(time.Hour).Add(-1*time.Hour).String()))
h.Write([]byte("UofMWeather/zip:get"))
fmt.Print(hex.EncodeToString(h.Sum(nil)), "\n")
// Reset our Hash
h.Reset()
// Hash of Timestamp rounded to this Hour
h.Write([]byte(time.Now().Round(time.Hour).String()))
h.Write([]byte("UofMWeather/zip:get"))
fmt.Print(hex.EncodeToString(h.Sum(nil)), "\n")
}
@momer
Copy link
Author

momer commented Sep 3, 2014

@cuzzea
Copy link

cuzzea commented Apr 29, 2022

Exactly what I was looking for. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment