Skip to content

Commit

Permalink
Merge pull request #422 from mysteriumnetwork/techdebt/move-from-satori
Browse files Browse the repository at this point in the history
moved to gofrs/uuid instead of satori/uuid
  • Loading branch information
vkuznecovas committed Oct 4, 2018
2 parents a987494 + 6c2db39 commit 23d2ce2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
18 changes: 9 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Expand Up @@ -54,8 +54,8 @@
version = "1.1.0"

[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.2.0"
name = "github.com/gofrs/uuid"
version = "3.1.1"

[[constraint]]
name = "github.com/stretchr/testify"
Expand Down
12 changes: 8 additions & 4 deletions session/generator.go
Expand Up @@ -17,9 +17,13 @@

package session

import "github.com/satori/go.uuid"
import "github.com/gofrs/uuid"

// GenerateUUID method returns ID based on random UUID
func GenerateUUID() ID {
return ID(uuid.NewV4().String())
// GenerateUUID method returns ID based on random UUID, or error if we fail to generate one
func GenerateUUID() (ID, error) {
uid, err := uuid.NewV4()
if err != nil {
return ID(""), err
}
return ID(uid.String()), nil
}
3 changes: 2 additions & 1 deletion session/generator_test.go
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestSessionIdLength(t *testing.T) {
sid := GenerateUUID()
sid, err := GenerateUUID()
assert.Nil(t, err)
assert.Len(t, sid, 36)
}
7 changes: 5 additions & 2 deletions session/manager.go
Expand Up @@ -31,7 +31,7 @@ var (
)

// IDGenerator defines method for session id generation
type IDGenerator func() ID
type IDGenerator func() (ID, error)

// ConfigProvider provides session config for remote client
type ConfigProvider func() (ServiceConfiguration, error)
Expand Down Expand Up @@ -102,7 +102,10 @@ func (manager *manager) Create(consumerID identity.Identity, proposalID int) (se
}

func (manager *manager) createSession(consumerID identity.Identity) (sessionInstance Session, err error) {
sessionInstance.ID = manager.generateID()
sessionInstance.ID, err = manager.generateID()
if err != nil {
return
}
sessionInstance.ConsumerID = consumerID
sessionInstance.Config, err = manager.provideConfig()
return
Expand Down
4 changes: 2 additions & 2 deletions session/manager_test.go
Expand Up @@ -45,8 +45,8 @@ func mockedConfigProvider() (ServiceConfiguration, error) {
return expectedSessionConfig, nil
}

func generateSessionID() ID {
return expectedID
func generateSessionID() (ID, error) {
return expectedID, nil
}

func saveSession(sessionInstance Session) {
Expand Down

0 comments on commit 23d2ce2

Please sign in to comment.