Skip to content

Commit

Permalink
Switch to google's UUID library
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jul 31, 2024
1 parent e195686 commit 55f9319
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.5
github.com/go-chi/chi/v5 v5.1.0
github.com/go-playground/validator/v10 v10.22.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/jellydator/ttlcache/v3 v3.2.0
github.com/jmoiron/sqlx v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jellydator/ttlcache/v3 v3.2.0 h1:6lqVJ8X3ZaUwvzENqPAobDsXNExfUJd61u++uW8a3LE=
Expand Down
16 changes: 3 additions & 13 deletions uuids/uuid.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package uuids

import (
"fmt"
"math/rand"
"regexp"

"github.com/nyaruka/gocommon/random"

"github.com/gofrs/uuid"
"github.com/google/uuid"
)

// V4Regex matches a string containing a valid v4 UUID
Expand Down Expand Up @@ -39,11 +38,7 @@ type defaultGenerator struct{}

// Next returns the next random UUID
func (g defaultGenerator) Next() UUID {
u, err := uuid.NewV4()
if err != nil {
// if we can't generate a UUID.. we're done
panic(fmt.Sprintf("unable to generate UUID: %s", err))
}
u := uuid.Must(uuid.NewRandom())
return UUID(u.String())
}

Expand All @@ -68,11 +63,6 @@ func NewSeededGenerator(seed int64) Generator {

// Next returns the next random UUID
func (g *seededGenerator) Next() UUID {
u := uuid.UUID{}
if _, err := g.rnd.Read(u[:]); err != nil {
panic(err)
}
u.SetVersion(uuid.V4)
u.SetVariant(uuid.VariantRFC4122)
u := uuid.Must(uuid.NewRandomFromReader(g.rnd))
return UUID(u.String())
}

0 comments on commit 55f9319

Please sign in to comment.