working on messaging library, adding branching options to client

This commit is contained in:
2020-06-02 17:08:44 -04:00
parent 33b1c78eb2
commit 0276a1d776
14 changed files with 89 additions and 135 deletions

View File

@@ -2,6 +2,9 @@ version = "0.1.5"
rootPath = ""
currentbranch = "master"
localbranches = ["master"]
remotebranches = ["master", "test", "test2"]
[[remote]]
name = "test2"
host = "localhost"

Binary file not shown.

View File

@@ -1,7 +1,6 @@
package clientcmd
import (
"bufio"
"encoding/json"
"fmt"
"net"
@@ -10,7 +9,7 @@ import (
"strconv"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/messages"
messages "github.com/deranjer/gvc/messages"
)
// ConfigPath is the global path to the config that is injected from the main client package.
@@ -76,25 +75,28 @@ func ConnectToServer(serverName string, branchName string, conf *clientconfig.Gv
port := ":" + strconv.Itoa(remote.Port)
connectionString := remote.Host + port
conn, err := net.Dial("tcp", connectionString)
defer conn.Close()
if err != nil {
return nil, fmt.Errorf("error connecting to %s", connectionString)
}
fmt.Println("Attempting connection on: ", connectionString)
decoder := json.NewDecoder(conn)
newMessage := messages.Cmd{}
var newMessage messages.Command
for { // Doing our 'handshake'
decoder.Decode(&newMessage)
message, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
return nil, fmt.Errorf("error reading from connection: %s", err)
}
fmt.Printf("Message from server: %s", message)
switch message {
case "Connected\n":
fmt.Println("Message from server", newMessage)
switch newMessage.CmdID {
case messages.CONNECTED:
fmt.Println("Server recognized client")
return &conn, nil
default:
return nil, fmt.Errorf("unexpected response from server: ", message)
fmt.Println("message: ", newMessage.CmdID)
return nil, fmt.Errorf("Unexpected message from server")
//return nil, fmt.Errorf("unexpected response from server: ", newMessage)
}
}
}

View File

@@ -2,12 +2,14 @@ package config
//Gvcconfig will be the struct that holds the entire client settings
type Gvcconfig struct {
Version string `toml:"version"`
RootPath string `toml:"rootPath"`
CurrentBranch string `toml:"currentbranch"`
Remotes []Remote `toml:"remote"` //The remote servers for the repo
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
Version string `toml:"version"`
RootPath string `toml:"rootPath"`
CurrentBranch string `toml:"currentbranch"`
LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches
RemoteBranches []string `toml:"remotebranches"` // RemoteBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches
Remotes []Remote `toml:"remote"` //The remote servers for the repo
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
}
//Remote will be a slice of remote server information

View File

@@ -1,12 +0,0 @@
module github.com/deranjer/gvc/client
go 1.14
replace derajnet.duckdns.org/git/deranjer/gvc => ../gvc //alias for local development
replace github.com/deranjer/gvc => ../gvc
require (
github.com/deranjer/clir v1.0.5
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031
)

View File

@@ -1,12 +0,0 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/deranjer/clir v1.0.5 h1:tEunZj5qJLYNBtzMQ/vH8hEAIv4NptWFmTldsP9U2qY=
github.com/deranjer/clir v1.0.5/go.mod h1:x/FAjr5CHGsBT0yjs+NYxX3qFxx8G15gbeCcN6FFuyU=
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031 h1:sPjxPMNILoBbu6uhDfa97AhlUhTgtPY2HqySAzuLd4o=
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031/go.mod h1:wPOs9IJ77lRTXyjEOQeegCFjIlm21qOFcv33lXmU7gE=
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

10
go.mod Normal file
View File

@@ -0,0 +1,10 @@
module github.com/deranjer/gvc
go 1.14
require (
github.com/deranjer/clir v1.0.5
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d
github.com/smartystreets/goconvey v1.6.4 // indirect
)

25
go.sum Normal file
View File

@@ -0,0 +1,25 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/deranjer/clir v1.0.5 h1:tEunZj5qJLYNBtzMQ/vH8hEAIv4NptWFmTldsP9U2qY=
github.com/deranjer/clir v1.0.5/go.mod h1:x/FAjr5CHGsBT0yjs+NYxX3qFxx8G15gbeCcN6FFuyU=
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031 h1:sPjxPMNILoBbu6uhDfa97AhlUhTgtPY2HqySAzuLd4o=
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031/go.mod h1:wPOs9IJ77lRTXyjEOQeegCFjIlm21qOFcv33lXmU7gE=
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d h1:3/oQzvZhwA8Jb5ykb0KehJfsdHokCJdC96k7xy6SJcs=
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d/go.mod h1:hGkv6sO57ZC+XrSTyzdIGXX7+O6S3RJb9G8sPopEF/4=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

1
gvc
View File

@@ -1 +0,0 @@
No files replaced

View File

@@ -1,7 +0,0 @@
module github.com/deranjer/gvc/messages
go 1.14
replace derajnet.duckdns.org/git/deranjer/gvc => ../gvc //alias for local development
replace github.com/deranjer/gvc => ../gvc

View File

@@ -5,7 +5,9 @@ type ID int
// ID forces all these commands to be locked in
const (
COMMIT ID = iota
ERROR ID = iota
COMMIT
CONNECTED
REFRESH
INFO
PUSH
@@ -17,7 +19,7 @@ const (
// Modifiers contains any arguments/modifiers to the command ID
type Modifiers struct {
ModifierID string
ModifierData string
ModifierData func()
}
// Command is the structure that all messages must adhere to

View File

@@ -1,9 +0,0 @@
module github.com/deranjer/gvc/server
go 1.14
replace derajnet.duckdns.org/git/deranjer/gvc => ../gvc //alias for local development
replace github.com/deranjer/gvc => ../gvc
require github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d // indirect

View File

@@ -1,71 +0,0 @@
github.com/Allenxuxu/eviop v0.0.0-20190901123806-035c218f739a/go.mod h1:I5+IvzRy5ddv0t9uiuUf4LsfJOXczEb9rxSuPWFfE0w=
github.com/Allenxuxu/gev v0.1.9 h1:6M8c8Ar3h5wqN+7kbXan+7aElECW4TLFP40TwsRxdLQ=
github.com/Allenxuxu/gev v0.1.9/go.mod h1:mWJzc8z0VtMo2amlupRpU13hapa5h1Zsy3pvwRVdwtI=
github.com/Allenxuxu/ringbuffer v0.0.0-20190803184500-fa400f2fe92b/go.mod h1:9Rg4D7ixiHGlU50BJWJEg6vwDFcGiOYKQFcHK6Vx9m4=
github.com/Allenxuxu/ringbuffer v0.0.6 h1:C1dRDXNPazonGogzgWRamLFDFgbHrqoNnG/MRdkIrgk=
github.com/Allenxuxu/ringbuffer v0.0.6/go.mod h1:F2Ela+/miJmKYwnXr3X0+spOmSEwL/iFAEzeUJ4SFMI=
github.com/Allenxuxu/toolkit v0.0.0-20190930031734-928c4d41e573 h1:ReuyJYr268gPqjonbliV6jKm5959pPtPdd18/FARdYs=
github.com/Allenxuxu/toolkit v0.0.0-20190930031734-928c4d41e573/go.mod h1:kamv5tj0iNT29zmKIYaxoIcYgDnzerxnOZiHBKbVp/o=
github.com/Allenxuxu/toolkit v0.0.0-20200426070240-464ad98cbe75 h1:e8swx/K1+tsQNgiweO9z9gJqYLSoy5FjyurhB5EG3KU=
github.com/Allenxuxu/toolkit v0.0.0-20200426070240-464ad98cbe75/go.mod h1:kamv5tj0iNT29zmKIYaxoIcYgDnzerxnOZiHBKbVp/o=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/RussellLuo/timingwheel v0.0.0-20191015104426-744130d33fdc h1:G8FpZoNs9aARNhSddx2OU6nXUbLX3sfghzoYCfPiLTg=
github.com/RussellLuo/timingwheel v0.0.0-20191015104426-744130d33fdc/go.mod h1:3VIJp8oOAlnDUnPy3kwyBGqsMiJJujqTP6ic9Jv6NbM=
github.com/RussellLuo/timingwheel v0.0.0-20191211035242-0e67dbf0ae97 h1:hTWutQkLyyHGn2DVHoGqDIlXzfYL+wumsFW62KChAIQ=
github.com/RussellLuo/timingwheel v0.0.0-20191211035242-0e67dbf0ae97/go.mod h1:3VIJp8oOAlnDUnPy3kwyBGqsMiJJujqTP6ic9Jv6NbM=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d h1:3/oQzvZhwA8Jb5ykb0KehJfsdHokCJdC96k7xy6SJcs=
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d/go.mod h1:hGkv6sO57ZC+XrSTyzdIGXX7+O6S3RJb9G8sPopEF/4=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kavu/go_reuseport v1.4.0/go.mod h1:CG8Ee7ceMFSMnx/xr25Vm0qXaj2Z4i5PWoUx+JZ5/CU=
github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw=
github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA=
github.com/panjf2000/gnet v0.0.1-rc.4/go.mod h1:N251s4H0wuPrB0ssD/D4ZQYOFJKZOwYxqIejzAodQqc=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/smartystreets-prototypes/go-disruptor v0.0.0-20180723194425-e0f8f9247cc2/go.mod h1:ACngBnuB+3ZLly6w2l5kkiUKwrH9kZRo+KKl7+jwhlA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tidwall/evio v1.0.2/go.mod h1:cYtY49LddNrlpsOmW7qJnqM8B2gOjrFrzT8+Fnb/GKs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190312203227-4b39c73a6495/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0 h1:7z820YPX9pxWR59qM7BE5+fglp4D/mKqAwCvGt11b+8=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ=
gonum.org/v1/plot v0.0.0-20190615073203-9aa86143727f/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

View File

@@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"log"
"github.com/deranjer/gvc/messages"
"github.com/firstrow/tcp_server"
@@ -10,21 +11,42 @@ import (
var version = "0.1"
//This is a generic error message so we make it 'global'
var errorMsg = messages.Command{
CmdID: messages.ERROR,
Body: []byte("Unrecognized Message"),
}
func main() {
errMsgJSON, _ := json.Marshal(errorMsg) //creating a []byte to easily send error message
server := tcp_server.New("localhost:9999")
server.OnNewClient(func(c *tcp_server.Client) {
// new client connected
// lets send some message
fmt.Println("New client connected....")
c.Send("Connected\n")
newMessage := messages.Command{
CmdID: messages.CONNECTED,
Body: []byte("Connected"),
}
jsonMessage, err := json.Marshal(newMessage)
if err != nil {
log.Fatalf("error creating new marshaller: %s", err)
}
c.Send(jsonMessage)
})
server.OnNewMessage(func(c *tcp_server.Client, message string) {
newMessage := json.Unmarshal(message, messages.Command)
fmt.Println("new Message from client: ", newMessage.CmdID)
server.OnNewMessage(func(c *tcp_server.Client, message []byte) {
var newMessage messages.Command
//messageBytes := []byte(message)
err := json.Unmarshal(message, &newMessage)
if err != nil {
c.Send(errMsgJSON)
fmt.Println("error reading message, closing connection to client")
c.Close()
}
fmt.Println("new Message from client: ", message)
switch newMessage.CmdID {
case "Details\n":
fmt.Println("Sending server details to client")
case messages.INFO:
fmt.Println("Sending server info to client")
detailsMessage := fmt.Sprintf("Server Details are as follows: Version: %s \n", version)
c.Send(detailsMessage)
default: