Created
April 14, 2016 17:40
-
-
Save genghisjahn/5980ce20c07598c4e1d2c282135d7110 to your computer and use it in GitHub Desktop.
MD5 Hash Any
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
//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