garritfra
6 years ago
4 changed files with 47 additions and 30 deletions
@ -0,0 +1,23 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"crypto/sha256" |
||||
"encoding/gob" |
||||
"encoding/hex" |
||||
) |
||||
|
||||
func calculateHash(obj interface{}) string { |
||||
var buffer bytes.Buffer |
||||
encoder := gob.NewEncoder(&buffer) |
||||
if err := encoder.Encode(obj); err != nil { |
||||
panic(err) |
||||
} |
||||
hasher := sha256.New() |
||||
bytes := buffer.Bytes() |
||||
hasher.Write(bytes) |
||||
|
||||
sum := hex.EncodeToString(hasher.Sum(nil)) |
||||
|
||||
return string(sum) |
||||
} |
Loading…
Reference in new issue