Browse Source

added docs and comments

master
Derek McQuay 5 years ago
parent
commit
b87a297986
No known key found for this signature in database GPG Key ID: 92A7BC0C86B0B91A
  1. 5
      README.md
  2. 6
      db.go
  3. 2
      parse.go

5
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.
[![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

@ -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

2
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, " ")

Loading…
Cancel
Save