Этот коммит содержится в:
=Corey Hulen
2015-12-09 15:42:48 -08:00
родитель 84aa572f67
Коммит 9fbe16c17b
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@@ -5,6 +5,7 @@ package model
import (
"bytes"
"crypto/rand"
"encoding/base32"
"encoding/json"
"fmt"
@@ -81,6 +82,17 @@ func NewId() string {
return b.String()
}
func NewRandomString(length int) string {
var b bytes.Buffer
str := make([]byte, length+8)
rand.Read(str)
encoder := base32.NewEncoder(encoding, &b)
encoder.Write(str)
encoder.Close()
b.Truncate(length) // removes the '==' padding
return b.String()
}
// GetMillis is a convience method to get milliseconds since epoch.
func GetMillis() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)