added docs and comments

This commit is contained in:
Derek McQuay
2017-03-14 20:09:02 -07:00
parent 4eae02d0e2
commit b87a297986
3 changed files with 12 additions and 1 deletions
+6
View File
@@ -2,6 +2,8 @@ package kvrepl
import "fmt"
// DB is struct defining two maps, pkv (points to kv) and nest, which
// aids figuring out how nested the commits are for current transaction
type DB struct {
KV1 map[string]string
KV2 map[string]string
@@ -9,6 +11,7 @@ type DB struct {
nest int
}
// read reads a key out of a map and checks for parsing errors
func read(args []string, kv map[string]string) (string, error) {
if len(args) != 1 {
return "", fmt.Errorf("incorrect usage: READ <key>")
@@ -20,6 +23,7 @@ func read(args []string, kv map[string]string) (string, error) {
return i, nil
}
// write writes key/value to map and checks for parsing errors
func write(args []string, kv map[string]string) error {
if len(args) != 2 {
return fmt.Errorf("incorrect usage: WRITE <key> <value>")
@@ -28,6 +32,7 @@ func write(args []string, kv map[string]string) error {
return nil
}
// del deletes a key from map and checks for parsing errors
func del(args []string, kv map[string]string) error {
if len(args) != 1 {
return fmt.Errorf("incorrect usage: DELETE <key>")
@@ -40,6 +45,7 @@ func del(args []string, kv map[string]string) error {
return nil
}
// whichDB returns which db is currently being written to
func whichDB(d *DB) map[string]string {
if d.PKV {
return d.KV1