Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Created April 14, 2016 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genghisjahn/5980ce20c07598c4e1d2c282135d7110 to your computer and use it in GitHub Desktop.
Save genghisjahn/5980ce20c07598c4e1d2c282135d7110 to your computer and use it in GitHub Desktop.
MD5 Hash Any
//MD5HashAny : will convert anything to a byte slice and return an MD5Hash
func MD5HashAny(s interface{}) string {
d, e := json.Marshal(&s)
if e != nil {
//I might regret this
return ""
}
return MD5HashBytes(d)
}
//MD5HashBytes takes a byte slice and returns a string MD5 Hash
func MD5HashBytes(data []byte) string {
h := md5.New()
io.WriteString(h, string(data))
return fmt.Sprintf("%x", h.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment