From 76907bb4022da64a18d45a7f6ee37d04f9536757 Mon Sep 17 00:00:00 2001
From: Jeromy <jeromyj@gmail.com>
Date: Mon, 22 Jan 2018 11:20:07 -0800
Subject: [PATCH] keystore interface docs

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
---
 keystore/keystore.go    | 22 +++++++++++++---------
 keystore/memkeystore.go |  4 +++-
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/keystore/keystore.go b/keystore/keystore.go
index fd9ab94b4..56dfd1b01 100644
--- a/keystore/keystore.go
+++ b/keystore/keystore.go
@@ -10,22 +10,25 @@ import (
 	ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
 )
 
+// Keystore provides a key management interface
 type Keystore interface {
-	// Has return whether or not a key exist in the Keystore
+	// Has returns whether or not a key exist in the Keystore
 	Has(string) (bool, error)
-	// Put store a key in the Keystore
+	// Put stores a key in the Keystore, if a key with the same name already exists, returns ErrKeyExists
 	Put(string, ci.PrivKey) error
-	// Get retrieve a key from the Keystore
+	// Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
+	// otherwise.
 	Get(string) (ci.PrivKey, error)
-	// Delete remove a key from the Keystore
+	// Delete removes a key from the Keystore
 	Delete(string) error
-	// List return a list of key identifier
+	// List returns a list of key identifier
 	List() ([]string, error)
 }
 
 var ErrNoSuchKey = fmt.Errorf("no key by the given name was found")
 var ErrKeyExists = fmt.Errorf("key by that name already exists, refusing to overwrite")
 
+// FSKeystore is a keystore backed by files in a given directory stored on disk.
 type FSKeystore struct {
 	dir string
 }
@@ -60,7 +63,7 @@ func NewFSKeystore(dir string) (*FSKeystore, error) {
 	return &FSKeystore{dir}, nil
 }
 
-// Has return whether or not a key exist in the Keystore
+// Has returns whether or not a key exist in the Keystore
 func (ks *FSKeystore) Has(name string) (bool, error) {
 	kp := filepath.Join(ks.dir, name)
 
@@ -77,7 +80,7 @@ func (ks *FSKeystore) Has(name string) (bool, error) {
 	return true, nil
 }
 
-// Put store a key in the Keystore
+// Put stores a key in the Keystore, if a key with the same name already exists, returns ErrKeyExists
 func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
 	if err := validateName(name); err != nil {
 		return err
@@ -108,7 +111,8 @@ func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
 	return err
 }
 
-// Get retrieve a key from the Keystore
+// Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
+// otherwise.
 func (ks *FSKeystore) Get(name string) (ci.PrivKey, error) {
 	if err := validateName(name); err != nil {
 		return nil, err
@@ -127,7 +131,7 @@ func (ks *FSKeystore) Get(name string) (ci.PrivKey, error) {
 	return ci.UnmarshalPrivateKey(data)
 }
 
-// Delete remove a key from the Keystore
+// Delete removes a key from the Keystore
 func (ks *FSKeystore) Delete(name string) error {
 	if err := validateName(name); err != nil {
 		return err
diff --git a/keystore/memkeystore.go b/keystore/memkeystore.go
index 3732a3262..6d07f6dc3 100644
--- a/keystore/memkeystore.go
+++ b/keystore/memkeystore.go
@@ -2,6 +2,8 @@ package keystore
 
 import ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
 
+// MemKeystore is an in memory keystore implementation that is not persisted to
+// any backing storage.
 type MemKeystore struct {
 	keys map[string]ci.PrivKey
 }
@@ -58,7 +60,7 @@ func (mk *MemKeystore) Delete(name string) error {
 // List return a list of key identifier
 func (mk *MemKeystore) List() ([]string, error) {
 	out := make([]string, 0, len(mk.keys))
-	for k, _ := range mk.keys {
+	for k := range mk.keys {
 		out = append(out, k)
 	}
 	return out, nil
-- 
GitLab