Easy and intuitive command line tool allows you to spin up a database avaliable from web or locally in a few seconds. Server can be run over a custom TCP protocol or over HTTP. Database can be be kept in memory only or persisted to a json file upon exit. You can also spin up a server from an existing file with or without modifying it. This is a hobby project and not meant for production use, but could be useful for testing/development phase.
The CLI tool is powered by cobra
Go 1.15 and newer
go install github.com/maracko/go-store@latest
Go versions older then 1.15
go get -u github.com/maracko/go-store
go-store [command] [argument] --flags
go-store help
can be used to get help on commands
go-store server HTTP -p 8888 -l /home/mario/database.json
This command will open and read the json file provided under -l
flag and start a HTTP server on port -p
You can then send HTTP requests to the server
Logs will be outputed to stdout in format Time
Method
URL
Host
2021/05/02 18:54:02 HTTP server started
2021/05/02 18:54:22 GET /testKey localhost:8888
- --location -l => Location of database file to read from (if blank or not provided a empty database in memory only will be initialised)
- --port -p => Port on which to start serving http
- --tls-port => Port on which to start serving https
- --memory -m => If present database won't be saved upon exit (even if read from a file first)
- --private-key -k => Used for HTTPS. Put a path to key
- --certificate -c => Used for HTTPS. Put a path to certificate
- --token -t => Used for auth. Send in
Authorization
header - --continous-write -c => If you want to keep saving the DB to the disks
- --write-interval -i => How many minutes to wait between writes. Default is 1 minute, if 0 will always write
http://{host}:{port}/{key}
- GET => returns key/keys
- POST => creates a new key
- PATCH => update existing key
- DELETE => delete key/keys
For retrieving operations just add key/s in the URI path. To retrieve multiple values set multiple keys split with a comma.
When you want to create/update keys you must send data inside request body in JSON format.
GET
http://localhost:8888/myKey
or
http://localhost:8888/myKey,myOtherKey,anotherKey
POST
http://localhost:8888
BODY =
{
"key": "myKey",
"value": "myValue"
}
PATCH
http://localhost:8888
BODY =
{
"key": "myKey",
"value": "myNewValue"
}
DELETE
http://localhost:8888/myKey
or
http://localhost:8888/myKey,myOtherKey,anotherKey
go-store server TCP -p 8888 -l /home/mario/database.json
2021/05/02 18:57:33 TCP server started
2021/05/02 18:58:09 Accepted connection from [::1]:34126
- --location -l => location of database file to read from (if blank or not provided a empty database in memory only will be initialised)
- --port -p => port on which to start serving http
- --memory -m => if present database won't be saved upon exit (even if read from a file first)
- --continous-write -c => if you want to keep saving the DB to the disks
- --write-interval -i => how many minutes to wait between writes. Default is 1 minute
go-store client -s localhost -p 9999
Welcome to go-store server!
2021/05/02 18:58:01 Connected to localhost:9999
$:set foo bar
Created new key foo
$:get foo
bar
$:
TCP currently only supports strings for both key and value, and will do no encoding on them (so no complex types)
go-store client -s localhost -p 8888
- --command -c => put a list of commands to execute and you will get output to stdout. Optionally chain them with
**
to execute them in sequence.
- get [key] => returns a single key
- set [key] [value] => set a new key
- upd [key] [value] => update existing key
- del [key] => deletes key