summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/model/utils.go b/model/utils.go
index 6d6eb452d..5596b06ff 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -5,10 +5,11 @@ package model
import (
"bytes"
- "code.google.com/p/go-uuid/uuid"
+ "crypto/rand"
"encoding/base32"
"encoding/json"
"fmt"
+ "github.com/pborman/uuid"
"io"
"net/mail"
"net/url"
@@ -53,7 +54,7 @@ func AppErrorFromJson(data io.Reader) *AppError {
if err == nil {
return &er
} else {
- return nil
+ return NewAppError("AppErrorFromJson", "could not decode", err.Error())
}
}
@@ -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)