Skip to content

Commit

Permalink
Use uuid.Must() as suggested upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Renström committed Jan 3, 2018
1 parent 84f2543 commit ad2da3a
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions shortuuid.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package shortuuid

import (
"fmt"
"strings"

uuid "github.com/satori/go.uuid"
Expand All @@ -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.Must(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.Must(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.Must(uuid.NewV4())
case strings.HasPrefix(name, "http"):
u = uuid.NewV5(uuid.NamespaceURL, name)
default:
Expand All @@ -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.Must(uuid.NewV4()))
}

0 comments on commit ad2da3a

Please sign in to comment.