Skip to content

Commit

Permalink
Merge pull request #13 from renstrom/use-github-google-uuid
Browse files Browse the repository at this point in the history
Use github.com/google/uuid instead of github.com/satori/go.uuid
  • Loading branch information
Peter Renström authored Feb 19, 2018
2 parents e8e2dcc + 3df12c3 commit 4faf8f3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ go:
- 1.8
- 1.9

env:
- DEP_VERSION="0.3.2" GO15VENDOREXPERIMENT=1

before_install:
- curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep
- chmod +x $GOPATH/bin/dep

install:
- dep ensure

script:
go test -v

Expand Down
3 changes: 0 additions & 3 deletions Gopkg.toml

This file was deleted.

6 changes: 3 additions & 3 deletions base57.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"strings"

uuid "github.com/satori/go.uuid"
"github.com/google/uuid"
)

type base57 struct {
Expand All @@ -23,7 +23,7 @@ func (b base57) Encode(u uuid.UUID) string {

// Calculate encoded length.
factor := math.Log(float64(25)) / math.Log(float64(b.alphabet.Length()))
length := math.Ceil(factor * float64(len(u.Bytes())))
length := math.Ceil(factor * float64(len(u)))

return b.numToString(&num, int(length))
}
Expand All @@ -35,7 +35,7 @@ func (b base57) Decode(u string) (uuid.UUID, error) {
if err != nil {
return uuid.Nil, err
}
return uuid.FromString(str)
return uuid.Parse(str)
}

// numToString converts a number a string using the given alpabet.
Expand Down
14 changes: 7 additions & 7 deletions shortuuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package shortuuid
import (
"strings"

uuid "github.com/satori/go.uuid"
"github.com/google/uuid"
)

// DefaultEncoder is the default encoder uses when generating new UUIDs, and is
Expand All @@ -18,12 +18,12 @@ type Encoder interface {

// New returns a new UUIDv4, encoded with base57.
func New() string {
return DefaultEncoder.Encode(uuid.NewV4())
return DefaultEncoder.Encode(uuid.New())
}

// NewWithEncoder returns a new UUIDv4, encoded with enc.
func NewWithEncoder(enc Encoder) string {
return enc.Encode(uuid.NewV4())
return enc.Encode(uuid.New())
}

// NewWithNamespace returns a new UUIDv5 (or v4 if name is empty), encoded with base57.
Expand All @@ -32,11 +32,11 @@ func NewWithNamespace(name string) string {

switch {
case name == "":
u = uuid.NewV4()
u = uuid.New()
case strings.HasPrefix(name, "http"):
u = uuid.NewV5(uuid.NamespaceURL, name)
u = uuid.NewSHA1(uuid.NameSpaceURL, []byte(name))
default:
u = uuid.NewV5(uuid.NamespaceDNS, name)
u = uuid.NewSHA1(uuid.NameSpaceDNS, []byte(name))
}

return DefaultEncoder.Encode(u)
Expand All @@ -46,5 +46,5 @@ func NewWithNamespace(name string) string {
// alternative alphabet abc.
func NewWithAlphabet(abc string) string {
enc := base57{newAlphabet(abc)}
return enc.Encode(uuid.NewV4())
return enc.Encode(uuid.New())
}
10 changes: 5 additions & 5 deletions shortuuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package shortuuid
import (
"testing"

uuid "github.com/satori/go.uuid"
"github.com/google/uuid"
)

var testVector = []struct {
Expand Down Expand Up @@ -181,7 +181,7 @@ func TestGeneration(t *testing.T) {

func TestEncoding(t *testing.T) {
for _, test := range testVector {
u, err := uuid.FromString(test.uuid)
u, err := uuid.Parse(test.uuid)
if err != nil {
t.Error(err)
}
Expand All @@ -196,7 +196,7 @@ func TestEncoding(t *testing.T) {

func TestDecoding(t *testing.T) {
for _, test := range testVector {
u1, err := uuid.FromString(test.uuid)
u1, err := uuid.Parse(test.uuid)
if err != nil {
t.Error(err)
}
Expand All @@ -215,7 +215,7 @@ func TestDecoding(t *testing.T) {
func TestNewWithAlphabet(t *testing.T) {
abc := DefaultAlphabet[:len(DefaultAlphabet)-1] + "="
enc := base57{newAlphabet(abc)}
u1, _ := uuid.FromString("e9ae9ba7-4fb1-4a6d-bbca-5315ed438371")
u1, _ := uuid.Parse("e9ae9ba7-4fb1-4a6d-bbca-5315ed438371")
u2 := enc.Encode(u1)
if u2 != "u=BFWRLr5dXbeWf==iasZi" {
t.Errorf("expected uuid to be %q, got %q", "u=BFWRLr5dXbeWf==iasZi", u2)
Expand All @@ -229,7 +229,7 @@ func BenchmarkUUID(b *testing.B) {
}

func BenchmarkEncoding(b *testing.B) {
u := uuid.NewV4()
u := uuid.New()
for i := 0; i < b.N; i++ {
DefaultEncoder.Encode(u)
}
Expand Down

0 comments on commit 4faf8f3

Please sign in to comment.