Skip to content

Commit 2aaf86d

Browse files
authored
Merge branch 'master' into saturdaysnipe
2 parents 2bbb732 + 790194d commit 2aaf86d

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

auth/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package auth
22

33
import (
4-
uuid "github.com/nu7hatch/gouuid"
4+
uuid "github.com/gofrs/uuid"
55
"github.com/writeas/web-core/log"
66
"strings"
77
)
@@ -16,7 +16,7 @@ func GetToken(header string) []byte {
1616
token = f[1]
1717
}
1818
}
19-
t, err := uuid.ParseHex(token)
19+
t, err := uuid.FromString(token)
2020
if err != nil {
2121
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
2222
} else {
@@ -31,7 +31,7 @@ func GetHeaderToken(header string) []byte {
3131
if len(header) > 0 {
3232
f := strings.Fields(header)
3333
if len(f) == 2 && f[0] == "Token" {
34-
t, err := uuid.ParseHex(f[1])
34+
t, err := uuid.FromString(f[1])
3535
if err != nil {
3636
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
3737
} else {

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ module github.com/writeas/web-core
33
go 1.10
44

55
require (
6+
github.com/gofrs/uuid v3.3.0+incompatible
67
github.com/kr/pretty v0.1.0 // indirect
78
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
8-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
99
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
1010
github.com/writeas/impart v1.1.0
11-
github.com/writeas/nerds v1.0.0
1211
github.com/writeas/openssl-go v1.0.0
1312
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613
1413
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect

go.sum

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU=
2+
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
3+
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
14
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
25
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
36
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
47
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
58
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
69
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspqypleMuJy4bzYEqlMhJnGAYpLrWe5p7W3CdvI=
710
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
8-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
9-
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
1011
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
1112
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
1213
github.com/writeas/impart v1.1.0 h1:nPnoO211VscNkp/gnzir5UwCDEvdHThL5uELU60NFSE=
1314
github.com/writeas/impart v1.1.0/go.mod h1:g0MpxdnTOHHrl+Ca/2oMXUHJ0PcRAEWtkCzYCJUXC9Y=
14-
github.com/writeas/nerds v1.0.0 h1:ZzRcCN+Sr3MWID7o/x1cr1ZbLvdpej9Y1/Ho+JKlqxo=
15-
github.com/writeas/nerds v1.0.0/go.mod h1:Gn2bHy1EwRcpXeB7ZhVmuUwiweK0e+JllNf66gvNLdU=
1615
github.com/writeas/openssl-go v1.0.0 h1:YXM1tDXeYOlTyJjoMlYLQH1xOloUimSR1WMF8kjFc5o=
1716
github.com/writeas/openssl-go v1.0.0/go.mod h1:WsKeK5jYl0B5y8ggOmtVjbmb+3rEGqSD25TppjJnETA=
1817
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 h1:MQ/ZZiDsUapFFiMS+vzwXkCTeEKaum+Do5rINYJDmxc=

id/random.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@ package id
22

33
import (
44
"fmt"
5-
"github.com/writeas/nerds/store"
5+
"crypto/rand"
66
)
77

8+
// GenerateRandomString creates a random string of characters of the given
9+
// length from the given dictionary of possible characters.
10+
//
11+
// This example generates a hexadecimal string 6 characters long:
12+
// GenerateRandomString("0123456789abcdef", 6)
13+
func GenerateRandomString(dictionary string, l int) string {
14+
var bytes = make([]byte, l)
15+
rand.Read(bytes)
16+
for k, v := range bytes {
17+
bytes[k] = dictionary[v%byte(len(dictionary))]
18+
}
19+
return string(bytes)
20+
}
21+
822
// GenSafeUniqueSlug generatees a reasonably unique random slug from the given
923
// original slug. It's "safe" because it uses 0-9 b-z excluding vowels.
1024
func GenSafeUniqueSlug(slug string) string {
11-
return fmt.Sprintf("%s-%s", slug, store.GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4))
25+
return fmt.Sprintf("%s-%s", slug, GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4))
1226
}

0 commit comments

Comments
 (0)