Last active
August 29, 2015 14:04
-
-
Save omeid/f29909fdc6611f0fa0f9 to your computer and use it in GitHub Desktop.
Golang utils for copypasta.
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 ( | |
"crypto/md5" | |
"crypto/rand" | |
"encoding/hex" | |
"encoding/json" | |
"io" | |
"net/http" | |
) | |
func RandomString() string { | |
id := make([]byte, 32) | |
_, err := io.ReadFull(rand.Reader, id) | |
if err != nil { | |
panic(err) // This shouldn't happen | |
} | |
return hex.EncodeToString(id) | |
} | |
func MD5(s string) string { | |
h := md5.Sum([]byte(s)) | |
return string(hex.EncodeToString(h[:])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
h := md5.Sum([]byte(s))
return string(hex.EncodeToString(h[:]))
Could be replaced with
return string(hex.EncodeToString(md5.Sum([]byte(s)) [:]))