Created
May 8, 2014 13:17
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
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
Just a few hash links showing usage, going to write a blog post here soon
http://play.golang.org/p/VgpRolcAMT
http://play.golang.org/p/laWKlg-38D
and timestamp
http://play.golang.org/p/RiAFHd-KYh
http://play.golang.org/p/vAZlpawyPH