Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d0d211b
Initial commit
SiarheiKresik Dec 3, 2018
ea4772a
Implement client
SiarheiKresik Dec 15, 2018
69a5d82
Add dockerfile
SiarheiKresik Dec 17, 2018
80a3267
Add gitignore file
SiarheiKresik Dec 17, 2018
cc457c7
Add makefile
SiarheiKresik Dec 17, 2018
5af629d
Update dockerfile
SiarheiKresik Dec 17, 2018
1f02fee
Update makefile
SiarheiKresik Dec 17, 2018
0921290
Update dockerfile
SiarheiKresik Dec 17, 2018
e7d2129
Update makefile
SiarheiKresik Dec 17, 2018
4ba8093
Update makefile
SiarheiKresik Dec 17, 2018
f4d8890
Add code checks into makefile
SiarheiKresik Dec 17, 2018
e3989f8
Update makefile
SiarheiKresik Dec 17, 2018
b748ad8
Refactor code checks in the makefile
SiarheiKresik Dec 18, 2018
1b60b6a
Set a image in the run-dev target to the dev-image
SiarheiKresik Dec 18, 2018
b9d512d
Add test targets into the makefile
SiarheiKresik Dec 18, 2018
efc01a1
Reorder check order in the makefile
SiarheiKresik Dec 18, 2018
ed3372d
Add coverage.out into gitignore
SiarheiKresik Dec 18, 2018
6f17329
Add test coverage target into the makefile
SiarheiKresik Dec 18, 2018
5454fd0
Add clean target into the makefile
SiarheiKresik Dec 18, 2018
b8703d6
Refactor the makefile
SiarheiKresik Dec 18, 2018
b8500aa
Implement client
SiarheiKresik Dec 18, 2018
3c88d85
Implement database
SiarheiKresik Dec 18, 2018
71ac094
Improve client log messages
SiarheiKresik Dec 19, 2018
73498de
Update gitignore
SiarheiKresik Dec 19, 2018
7c7f346
Implement database
SiarheiKresik Dec 19, 2018
2bb639d
Implement server
SiarheiKresik Dec 19, 2018
3c4868c
Refactor client
SiarheiKresik Dec 19, 2018
d253adc
Fix coverage target of the makefile
SiarheiKresik Dec 19, 2018
f6e3543
Add .editorconfig
SiarheiKresik Dec 19, 2018
da3d544
Refactor KEY command to filter keys by glob pattern
SiarheiKresik Dec 20, 2018
7269f88
Update code comments
SiarheiKresik Dec 20, 2018
06b2faf
Fix typo
SiarheiKresik Dec 20, 2018
0cc3bea
Add comments
SiarheiKresik Dec 20, 2018
e8dcb3a
Remove unnecessary log print
SiarheiKresik Dec 20, 2018
582fa27
Implement verbose server mode and client ids
SiarheiKresik Dec 20, 2018
636527c
Make logs formatting more consistent
SiarheiKresik Dec 20, 2018
7a41945
Now server keep on running after accept error
SiarheiKresik Dec 20, 2018
b381169
Remove unneccesery code
SiarheiKresik Dec 20, 2018
7fda69c
Make string formatting more consistent
SiarheiKresik Dec 20, 2018
24d9aac
Update readme file
SiarheiKresik Dec 20, 2018
1fe248e
Fix type in the readme file
SiarheiKresik Dec 20, 2018
95182c0
Add comments
SiarheiKresik Dec 20, 2018
f489399
Fix typo
SiarheiKresik Dec 20, 2018
771af49
Correct log message
SiarheiKresik Dec 20, 2018
c82f95c
Refactor database tests
SiarheiKresik Dec 20, 2018
203cf21
Remove client flags for non implemented features
SiarheiKresik Dec 20, 2018
a32d74b
Update readme file
SiarheiKresik Dec 20, 2018
6eb8112
Update readme file
SiarheiKresik Dec 20, 2018
d577ce3
Remove wrong setting from the editorconfig
SiarheiKresik Dec 20, 2018
6b39598
Add comments
SiarheiKresik Dec 20, 2018
e186d85
Remove trailing whitespaces to pass goimports check
SiarheiKresik Dec 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement client
  • Loading branch information
SiarheiKresik committed Dec 15, 2018
commit ea4772ab30872f31f75463097834b4099524a3fe
46 changes: 46 additions & 0 deletions client/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"flag"
)

type Config struct {
port int
host string
dump bool
restore bool
}

var config Config

func init() {
const (
defaultPort = 9090
portDesc = "The port to connect to the server"

defaultHost = "127.0.0.1"
hostDesc = "The host to connect to the server"

defaultDump = false
dumpDesc = "Dump the whole database to the JSON format on STDOUT"

defaultRestore = false
restoreDesc = "Restore the database from the dumped file"
)

shorhand := " (shorthand)"

flag.IntVar(&config.port, "port", defaultPort, portDesc)
flag.IntVar(&config.port, "p", defaultPort, portDesc+shorhand)

flag.StringVar(&config.host, "host", defaultHost, hostDesc)
flag.StringVar(&config.host, "h", defaultHost, hostDesc+shorhand)

flag.BoolVar(&config.dump, "dump", defaultDump, dumpDesc)
flag.BoolVar(&config.dump, "d", defaultDump, dumpDesc+shorhand)

flag.BoolVar(&config.restore, "restore", defaultRestore, restoreDesc)
flag.BoolVar(&config.restore, "r", defaultRestore, restoreDesc+shorhand)

flag.Parse()
}
57 changes: 57 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"bufio"
"fmt"
"log"
"net"
"os"
"strconv"

_ "github.com/SiarheiKresik/go-kvdb/common"
)

func main() {

const protocol = "tcp"

addr := net.JoinHostPort(config.host, strconv.Itoa(config.port))
// TODO check if host and port are valid

log.Println("Connecting to server ", addr, "...")

conn, err := net.Dial(protocol, addr)
if err != nil {
log.Fatalln(err)
}
defer conn.Close()

remoteAddr := conn.RemoteAddr()
reader := bufio.NewReader(os.Stdin)

for {
// command line prompt
fmt.Print("server: ", remoteAddr, " > ")

// read in input from stdin
text, err := reader.ReadString('\n')
if err != nil {
log.Fatalln("text error:", err)
}

// send to socket
_, prnterr := fmt.Fprintf(conn, text)
if prnterr != nil {
log.Fatalln(prnterr)
}

// listen for reply
message, readerr := bufio.NewReader(conn).ReadString('\n')
if readerr != nil {
log.Fatalln(readerr)
break
}
fmt.Print(message)

}
}