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 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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly what I was looking for. Thanks!