Skip to content

Commit

Permalink
refactor: idgen pkg (#1715)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi committed Sep 29, 2022
1 parent 4584ef0 commit 8890feb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 65 deletions.
7 changes: 3 additions & 4 deletions client/dfget/dfget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"d7y.io/dragonfly/v2/client/config"
"d7y.io/dragonfly/v2/pkg/digest"
"d7y.io/dragonfly/v2/pkg/idgen"
"d7y.io/dragonfly/v2/pkg/source"
"d7y.io/dragonfly/v2/pkg/source/mocks"
)

func Test_downloadFromSource(t *testing.T) {
homeDir, err := os.UserHomeDir()
assert.Nil(t, err)
output := filepath.Join(homeDir, idgen.UUIDString())
output := filepath.Join(homeDir, uuid.New().String())
defer os.Remove(output)

content := idgen.UUIDString()

content := uuid.New().String()
sourceClient := mocks.NewMockResourceClient(gomock.NewController(t))
require.Nil(t, source.Register("http", sourceClient, func(request *source.Request) *source.Request {
return request
Expand Down
1 change: 1 addition & 0 deletions pkg/idgen/host_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
)

// HostID generates a host id.
func HostID(hostname string, port int32) string {
return fmt.Sprintf("%s-%d", hostname, port)
}
10 changes: 3 additions & 7 deletions pkg/idgen/peer_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import (
"github.com/google/uuid"
)

var pid int

func init() {
pid = os.Getpid()
}

// PeerID generates a peer id.
func PeerID(ip string) string {
return fmt.Sprintf("%s-%d-%s", ip, pid, uuid.New())
return fmt.Sprintf("%s-%d-%s", ip, os.Getpid(), uuid.New())
}

// SeedPeerID generates a seed peer id.
func SeedPeerID(ip string) string {
return fmt.Sprintf("%s_%s", PeerID(ip), "Seed")
}
25 changes: 0 additions & 25 deletions pkg/idgen/uuid.go

This file was deleted.

29 changes: 0 additions & 29 deletions pkg/idgen/uuid_test.go

This file was deleted.

0 comments on commit 8890feb

Please sign in to comment.