Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Last active May 22, 2018 06:52
Show Gist options
  • Save nukosuke/e829d15db895c8f4ffb27fde8fd285aa to your computer and use it in GitHub Desktop.
Save nukosuke/e829d15db895c8f4ffb27fde8fd285aa to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"crypto/md5"
"encoding/gob"
"fmt"
)
type Data struct {
Field1 string
Field2 int
FIeld3 bool
}
func main() {
d1 := Data{"てすと", 100, true}
d2 := Data{"てすと", 100, true}
buf1 := bytes.NewBuffer(nil)
_ = gob.NewEncoder(buf1).Encode(&d1)
fmt.Println(md5.Sum(buf1.Bytes()))
buf2 := bytes.NewBuffer(nil)
_ = gob.NewEncoder(buf2).Encode(&d2)
fmt.Println(md5.Sum(buf2.Bytes()))
}
@nukosuke
Copy link
Author

nukosuke commented May 22, 2018

gobではアドレスなどの情報が含まれていないっぽく同じ内容のデータは同じハッシュ値になる。

➜  e829d15db895c8f4ffb27fde8fd285aa git:(master) ✗ ./e829d15db895c8f4ffb27fde8fd285aa
[236 182 205 206 133 206 179 244 172 218 225 46 134 252 83 253]
[236 182 205 206 133 206 179 244 172 218 225 46 134 252 83 253]

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