Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
replace uuidv4 with uuidv5
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Sep 16, 2023
1 parent e57fc62 commit 27055cb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions epub.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ import (
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"time"

// TODO: Eventually this should include the major version (e.g. github.com/gofrs/uuid/v3) but that would break
// compatibility with Go < 1.9 (https://github.com/golang/go/wiki/Modules#semantic-import-versioning)
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
"github.com/vincent-petithory/dataurl"
)

Expand Down Expand Up @@ -186,7 +186,7 @@ func NewEpub(title string) (*Epub, error) {
return nil, fmt.Errorf("can't create NewEpub: %w", err)
}
// Set minimal required attributes
e.SetIdentifier(urnUUIDPrefix + uuid.Must(uuid.NewV4()).String())
e.SetIdentifier(urnUUIDPrefix + uuid.NewV5(uuid.NamespaceURL, strconv.FormatInt(time.Now().UnixNano(), 10)).String())
e.SetLang(defaultEpubLang)
e.SetTitle(title)

Expand Down
8 changes: 6 additions & 2 deletions epub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"testing"
"time"

"github.com/go-shiori/go-epub/internal/storage"
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
)

const (
Expand Down Expand Up @@ -1324,7 +1325,10 @@ func validateEpub(t testing.TB, epubFilename string) ([]byte, error) {
}

func writeAndExtractEpub(t testing.TB, e *Epub, epubFilename string) string {
tempDir := uuid.Must(uuid.NewV4()).String()
//tempDir := uuid.NewV5(uuid.NamespaceURL, "github.com/go-shiori/go-epub").String()

tempDir := uuid.NewV5(uuid.NamespaceURL, strconv.FormatInt(time.Now().UnixNano(), 10)).String()

err := filesystem.Mkdir(tempDir, 0777)
if err != nil {
t.Errorf("Unexpected error creating temp dir: %s", err)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.20

require (
github.com/gabriel-vasile/mimetype v1.4.2
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gofrs/uuid/v5 v5.0.0
github.com/vincent-petithory/dataurl v1.0.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
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/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
Expand Down
4 changes: 3 additions & 1 deletion write.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"log"
"os"
"path/filepath"
"strconv"
"time"

"github.com/gofrs/uuid/v5"
)
Expand Down Expand Up @@ -55,7 +57,7 @@ const (
func (e *Epub) WriteTo(dst io.Writer) (int64, error) {
e.Lock()
defer e.Unlock()
tempDir := uuid.Must(uuid.NewV4()).String()
tempDir := uuid.NewV5(uuid.NamespaceURL, strconv.FormatInt(time.Now().UnixNano(), 10)).String()

err := filesystem.Mkdir(tempDir, dirPermissions)
if err != nil {
Expand Down

0 comments on commit 27055cb

Please sign in to comment.