From 9a905fd2cc8f2645bcde2c35b890510805ecaedb Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 9 Sep 2016 17:38:10 -0400 Subject: [PATCH] Add exported funcs documentation --- store/random.go | 9 +++++++++ store/store.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/store/random.go b/store/random.go index cb2fd37..fac8820 100644 --- a/store/random.go +++ b/store/random.go @@ -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) diff --git a/store/store.go b/store/store.go index cd62838..179745d 100644 --- a/store/store.go +++ b/store/store.go @@ -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)