1
0
mirror of https://github.com/writeas/nerds synced 2018-07-20 12:35:21 +00:00

Add exported funcs documentation

This commit is contained in:
Matt Baer 2016-09-09 17:38:10 -04:00
parent 98920a9d1f
commit 9a905fd2cc
2 changed files with 12 additions and 0 deletions

View File

@ -4,14 +4,23 @@ import (
"crypto/rand"
)
// Generate62RandomString creates a random string with the given length
// consisting of characters in [A-Za-z0-9].
func Generate62RandomString(l int) string {
return GenerateRandomString("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", l)
}
// GenerateFriendlyRandomString creates a random string of characters with the
// given length consististing of characters in [a-z0-9].
func GenerateFriendlyRandomString(l int) string {
return GenerateRandomString("0123456789abcdefghijklmnopqrstuvwxyz", l)
}
// GenerateRandomString creates a random string of characters of the given
// length from the given dictionary of possible characters.
//
// This example generates a hexadecimal string 6 characters long:
// GenerateRandomString("0123456789abcdef", 6)
func GenerateRandomString(dictionary string, l int) string {
var bytes = make([]byte, l)
rand.Read(bytes)

View File

@ -7,9 +7,12 @@ import (
)
const (
// FriendlyIdLen is the length of any saved posts's filename.
FriendlyIdLen = 13
)
// SavePost writes the given bytes to a file with a randomly generated name in
// the given directory.
func SavePost(outDir string, post []byte) (string, error) {
filename := generateFileName()
f, err := os.Create(outDir + "/" + filename)