From 4a9e0597559f196cadb84d4e1b0cafac7b350018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:27:58 +0100 Subject: [PATCH 01/10] Revert "Use `uuid.Must()` as suggested upstream" This reverts commit ad2da3a85aa0a3fdf94f60e971cdc48b572d0e88. --- shortuuid.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/shortuuid.go b/shortuuid.go index cbb30af..f26f4d9 100644 --- a/shortuuid.go +++ b/shortuuid.go @@ -1,6 +1,7 @@ package shortuuid import ( + "fmt" "strings" uuid "github.com/satori/go.uuid" @@ -18,21 +19,33 @@ type Encoder interface { // New returns a new UUIDv4, encoded with base57. func New() string { - return DefaultEncoder.Encode(uuid.Must(uuid.NewV4())) + str, err := uuid.NewV4() + if err != nil { + panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) + } + return DefaultEncoder.Encode(str) } // NewWithEncoder returns a new UUIDv4, encoded with enc. func NewWithEncoder(enc Encoder) string { - return enc.Encode(uuid.Must(uuid.NewV4())) + str, err := uuid.NewV4() + if err != nil { + panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) + } + return enc.Encode(str) } // NewWithNamespace returns a new UUIDv5 (or v4 if name is empty), encoded with base57. func NewWithNamespace(name string) string { var u uuid.UUID + var err error switch { case name == "": - u = uuid.Must(uuid.NewV4()) + u, err = uuid.NewV4() + if err != nil { + panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) + } case strings.HasPrefix(name, "http"): u = uuid.NewV5(uuid.NamespaceURL, name) default: @@ -46,5 +59,9 @@ func NewWithNamespace(name string) string { // alternative alphabet abc. func NewWithAlphabet(abc string) string { enc := base57{newAlphabet(abc)} - return enc.Encode(uuid.Must(uuid.NewV4())) + str, err := uuid.NewV4() + if err != nil { + panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) + } + return enc.Encode(str) } From b9dd8764de1af583925f792091ba30b85b80410a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:28:06 +0100 Subject: [PATCH 02/10] Revert "formatting imports." This reverts commit 19d263e7d0764537a10c248ae849363f109e040e. --- shortuuid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shortuuid.go b/shortuuid.go index f26f4d9..fa8ce69 100644 --- a/shortuuid.go +++ b/shortuuid.go @@ -1,10 +1,10 @@ package shortuuid import ( - "fmt" "strings" uuid "github.com/satori/go.uuid" + "fmt" ) // DefaultEncoder is the default encoder uses when generating new UUIDs, and is From 0247ea7990656868302990262654ddd02d8f336a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:28:08 +0100 Subject: [PATCH 03/10] Revert "Quick & Dirty update to support upstream changes." This reverts commit 18fb139e904718c29b803eaddfd0408d698200b5. --- shortuuid.go | 25 ++++--------------------- shortuuid_test.go | 6 +----- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/shortuuid.go b/shortuuid.go index fa8ce69..3bb69da 100644 --- a/shortuuid.go +++ b/shortuuid.go @@ -4,7 +4,6 @@ import ( "strings" uuid "github.com/satori/go.uuid" - "fmt" ) // DefaultEncoder is the default encoder uses when generating new UUIDs, and is @@ -19,33 +18,21 @@ type Encoder interface { // New returns a new UUIDv4, encoded with base57. func New() string { - str, err := uuid.NewV4() - if err != nil { - panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) - } - return DefaultEncoder.Encode(str) + return DefaultEncoder.Encode(uuid.NewV4()) } // NewWithEncoder returns a new UUIDv4, encoded with enc. func NewWithEncoder(enc Encoder) string { - str, err := uuid.NewV4() - if err != nil { - panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) - } - return enc.Encode(str) + return enc.Encode(uuid.NewV4()) } // NewWithNamespace returns a new UUIDv5 (or v4 if name is empty), encoded with base57. func NewWithNamespace(name string) string { var u uuid.UUID - var err error switch { case name == "": - u, err = uuid.NewV4() - if err != nil { - panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) - } + u = uuid.NewV4() case strings.HasPrefix(name, "http"): u = uuid.NewV5(uuid.NamespaceURL, name) default: @@ -59,9 +46,5 @@ func NewWithNamespace(name string) string { // alternative alphabet abc. func NewWithAlphabet(abc string) string { enc := base57{newAlphabet(abc)} - str, err := uuid.NewV4() - if err != nil { - panic(fmt.Sprintf("Unable to create UUIDv4: %s", err)) - } - return enc.Encode(str) + return enc.Encode(uuid.NewV4()) } diff --git a/shortuuid_test.go b/shortuuid_test.go index f45dc21..73761a8 100644 --- a/shortuuid_test.go +++ b/shortuuid_test.go @@ -229,11 +229,7 @@ func BenchmarkUUID(b *testing.B) { } func BenchmarkEncoding(b *testing.B) { - u, err := uuid.NewV4() - if err != nil { - b.Logf("Unable to create UUIDv4: %s", err) - b.FailNow() - } + u := uuid.NewV4() for i := 0; i < b.N; i++ { DefaultEncoder.Encode(u) } From fbd4557d245604acb2d03410893d1d8823ff7323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:29:21 +0100 Subject: [PATCH 04/10] Add Gopkg.toml to pin satori/go.uuid to v1.2 Hopefully this should take care of the unreleased breaking changes introduced in `github.com/satori/go.uuid`. For more info about this, see https://github.com/satori/go.uuid/issues/66. --- Gopkg.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Gopkg.toml diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..731c849 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + name = "github.com/satori/go.uuid" + version = "1.2" From bab7fc422c37d802aee825b3fe4ee672c0aab4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:32:44 +0100 Subject: [PATCH 05/10] Add vendor directory to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor From 1e1eeddc1ce2d489b1a2c25e77a5cf744818fd75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:38:30 +0100 Subject: [PATCH 06/10] Use `dep` in Travis to manage dependencies https://github.com/golang/dep/blob/master/docs/FAQ.md#how-do-i-use-dep-in-ci --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 61dfd13..dd01df4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,16 @@ go: - 1.8 - 1.9 +env: + - DEP_VERSION="0.3.2" + +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 From cf9541f2c0e76ab0639eccbb3ea9748d952f099c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:41:26 +0100 Subject: [PATCH 07/10] Remove Go 1.4 from test matrix Vendoring was first introduced in Go 1.5 under an experimental flag. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd01df4..d6f5fd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: go go: - - 1.4 - - 1.5 - 1.6 - 1.7 - 1.8 From 89ecb09a32defd84d666651a44bda80b8c33c9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:45:26 +0100 Subject: [PATCH 08/10] Add GO15VENDOREXPERIMENT to Travis for vendor support --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d6f5fd5..7624801 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ go: 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 From 61da39fad35ee6d5218e1da9cf7f0c4263d11b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:49:34 +0100 Subject: [PATCH 09/10] Fix Travis env variable syntax Previously, one build per env line was triggered. --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7624801..3e6c8c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,7 @@ go: - 1.9 env: - - DEP_VERSION="0.3.2" - - GO15VENDOREXPERIMENT=1 + - 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 From 37315b2655d1aa00deae04625fbc94c0eb3e2ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Renstro=CC=88m?= Date: Mon, 15 Jan 2018 09:51:51 +0100 Subject: [PATCH 10/10] Add back accidentally removed Go 1.5 For Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3e6c8c0..eb3d8ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go go: + - 1.5 - 1.6 - 1.7 - 1.8