From f814a0b6304107a2e4d5f60d4eade5948a2ad401 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 28 Jan 2019 19:49:28 +0000 Subject: [PATCH] change the interface not to use pointer this will save some conversion of calling function Signed-off-by: Leo Chen --- internal/utils/utils.go | 8 ++++---- internal/utils/utils_test.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 1ab0543c2..a50444048 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -156,7 +156,7 @@ func Load(path string, v interface{}) error { } // LoadPrivateKey parses the key string in base64 format and return PrivKey -func LoadPrivateKey(key string) (*p2p_crypto.PrivKey, error) { +func LoadPrivateKey(key string) (p2p_crypto.PrivKey, error) { if key != "" { k1, err := p2p_crypto.ConfigDecodeKey(key) if err != nil { @@ -166,15 +166,15 @@ func LoadPrivateKey(key string) (*p2p_crypto.PrivKey, error) { if err != nil { return nil, fmt.Errorf("failed to unmarshal private key: %v", err) } - return &priKey, nil + return priKey, nil } return nil, fmt.Errorf("empty key string") } // SavePrivateKey convert the PrivKey to base64 format and return string -func SavePrivateKey(key *p2p_crypto.PrivKey) (string, error) { +func SavePrivateKey(key p2p_crypto.PrivKey) (string, error) { if key != nil { - b, err := p2p_crypto.MarshalPrivateKey(*key) + b, err := p2p_crypto.MarshalPrivateKey(key) if err != nil { return "", fmt.Errorf("failed to marshal private key: %v", err) } diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 52a9a05f9..d7cea4454 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -106,7 +106,7 @@ func TestSaveLoadPrivateKey(t *testing.T) { if err != nil { t.Fatalf("failed to generate p2p key: %v", err) } - str, err := SavePrivateKey(&pk) + str, err := SavePrivateKey(pk) if err != nil { t.Fatalf("failed to save private key: %v", err) } @@ -116,10 +116,10 @@ func TestSaveLoadPrivateKey(t *testing.T) { t.Fatalf("failed to load key: %v", err) } - if !crypto.KeyEqual(pk, *pk1) { + if !crypto.KeyEqual(pk, pk1) { t.Errorf("loaded key is not right") b1, _ := pk.Bytes() - b2, _ := (*pk1).Bytes() + b2, _ := pk1.Bytes() t.Errorf("expecting pk: %v\n", b1) t.Errorf("got pk1: %v\n", b2) }