added docs and comments
This commit is contained in:
parent
4eae02d0e2
commit
b87a297986
@ -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.
|
||||
[![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.
|
||||
|
6
db.go
6
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 <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
|
||||
|
Loading…
Reference in New Issue
Block a user