diff --git a/README.md b/README.md index fb37fc4..19fa482 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # kvrepl -A simple command line REPL (read-eval-print loop) that drives a simple in-memory key/value storage system. This system should also allow for nested transactions. A transaction can then be committed or aborted. \ No newline at end of file +[![GoDoc](https://godoc.org/s.mcquay.me/dm/kvrepl?status.svg)](https://godoc.org/s.mcquay.me/dm/kvrepl) +[![Go Report Card](https://goreportcard.com/badge/s.mcquay.me/dm/kvrepl)](https://goreportcard.com/report/s.mcquay.me/dm/kvrepl) + +A simple command line REPL (read-eval-print loop) that drives a simple in-memory key/value storage system. This system should also allow for nested transactions. A transaction can then be committed or aborted. diff --git a/db.go b/db.go index 585bab0..cbce147 100644 --- a/db.go +++ b/db.go @@ -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 ") @@ -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 ") @@ -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 ") @@ -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 diff --git a/parse.go b/parse.go index 66b0733..db957cf 100644 --- a/parse.go +++ b/parse.go @@ -6,6 +6,8 @@ import ( "strings" ) +// Parse decides what commands to run and returns a string containing the +// value of a read or an error if one occured. func Parse(s string, d *DB) (string, error) { args := strings.Split(s, " ")