starting client/server connection

This commit is contained in:
2020-05-31 18:42:38 -04:00
parent 6ae1705ef0
commit 0051b92c47
9 changed files with 439 additions and 11 deletions

View File

@@ -1,7 +1,14 @@
version = "0.1.5"
rootPath = ""
[[remote]]
name = "test"
host = "localhost"
port = 9999
[ignore]
files = ["client1.exe", "client2.exe", "client3.exe", "client4.exe", "client5.exe", "client6.exe", "client7.exe", "test1\\client8.exe", "clientcmd\\init.go"]
exts = [".exe", ".tl"]
[nocompress]

View File

@@ -25,7 +25,7 @@ func main() {
var err error
rootPath, err = os.Getwd()
if err != nil {
log.Fatalf("Can't get working dir, permissions issue %s", err)
log.Fatalf("Can't get working dir, permissions issue? %s", err)
}
// Setting up a blank config to read the .toml file in if one exists
@@ -34,7 +34,8 @@ func main() {
if isRepo {
err := store.Load(configPath, &conf)
if err != nil {
fmt.Println("Error loading config file into struct! ", err)
fmt.Printf("Error loading config file into struct, please fix config, panic! \n%s", err)
os.Exit(0)
}
err = clientconfig.ValidateConfig(&conf, version)
if err != nil {
@@ -54,10 +55,17 @@ func main() {
// Adding the ignore commands
ignoreCommands(cli, &conf)
// Adding the test commands
infoCommands(cli, &conf)
err = cli.Run()
if err != nil {
fmt.Printf("Error occurred: %v\n", err)
}
err = store.Save(configPath, conf)
if err != nil {
fmt.Println("Error saving config to file, changes were not writted! Check config file... ", err)
}
}
// injectVariables just injects the global variables into the packages
@@ -211,16 +219,16 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
return fmt.Errorf("incorrect input detected, please fix and retry")
}
if file != "" { // if the file flag was used it won't be empty
fmt.Println("Ignoring file to tracked files: ", file)
err := clientcmd.IgnoreFiles(file, "file", conf.Ignores)
//fmt.Println("Ignoring file: ", file)
err := clientcmd.IgnoreFiles(file, "file", conf)
if err != nil {
return err
}
return nil
}
if folder != "" { // if the folder flag was used it won't be empty
fmt.Println("Ignoring contents of folder to tracked files: ", folder)
err := clientcmd.IgnoreFiles(folder, "folder", conf.Ignores)
fmt.Println("Ignoring contents of folder: ", folder)
err := clientcmd.IgnoreFiles(folder, "folder", conf)
if err != nil {
return err
}
@@ -228,7 +236,62 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
}
if wildcard != "" { // if the wildcard flag was used it won't be empty
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf.Ignores)
err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf)
if err != nil {
return err
}
return nil
}
return nil
})
// Adding the remove ignore command (remove from the ignore list)
removeIgnoreCmd(ignoreCmd, conf)
}
// removeIgnoreCmd removes files/folders/wildcard from the ignore list
func removeIgnoreCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
removeIgnoreCmd := ignoreCmd.NewSubCommand("remove", "remove from ignores file(s)/folder(s) (recursively for folder) to repo")
removeIgnoreCmd.LongDescription("You can remove from ignore all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt")
//File/Folder/Wildcard Ignoring
var file string
var folder string
var wildcard string
fileFlag := removeIgnoreCmd.StringFlag("file", "removes ignored file from config", &file)
fileFlag.FlagShortCut("file", "f")
folderFlag := removeIgnoreCmd.StringFlag("folder", "removes ignored folder", &folder)
folderFlag.FlagShortCut("folder", "fd")
wildCardFlag := removeIgnoreCmd.StringFlag("wildcard", "removes wildcard from ignores", &wildcard)
wildCardFlag.FlagShortCut("wildcard", "wc")
removeIgnoreCmd.Action(func() error {
isRepo := validateRepo()
if !isRepo {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
if len(removeIgnoreCmd.OtherArgs()) > 0 {
removeIgnoreCmd.PrintHelp()
return fmt.Errorf("incorrect input detected, please fix and retry")
}
if file != "" { // if the file flag was used it won't be empty
//fmt.Println("Ignoring file: ", file)
err := clientcmd.RemoveIgnoreFiles(file, "file", conf)
if err != nil {
return err
}
return nil
}
if folder != "" { // if the folder flag was used it won't be empty
fmt.Println("Ignoring contents of folder: ", folder)
err := clientcmd.RemoveIgnoreFiles(folder, "folder", conf)
if err != nil {
return err
}
return nil
}
if wildcard != "" { // if the wildcard flag was used it won't be empty
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
err := clientcmd.RemoveIgnoreFiles(wildcard, "wildcard", conf)
if err != nil {
return err
}
@@ -237,3 +300,78 @@ func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
return nil
})
}
func infoCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
//All the test commands
infoCmd := cli.NewSubCommand("info", "tests various aspects of the client/files/etc and server")
infoCmd.LongDescription("You can get information on remotes, files, etc")
remoteInfoCmd := infoCmd.NewSubCommand("remote", "takes the suppled server name and gets information about the server")
remoteInfoCmd.Action(func() error {
isRepo := validateRepo()
if !isRepo {
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
os.Exit(0)
}
if len(remoteInfoCmd.OtherArgs()) == 0 {
remoteInfoCmd.PrintHelp()
return fmt.Errorf("Please supply a server name to test a remote")
}
server := remoteInfoCmd.OtherArgs()[0]
conn, err := clientcmd.ConnectToServer(server, "master", conf)
if err != nil {
return err
}
err = clientcmd.GetServerInfo(conn)
if err != nil {
return err
}
return nil
})
// //File/Folder/Wildcard Ignoring
// var file string
// var folder string
// var wildcard string
// fileFlag := ignoreCmd.StringFlag("file", "adds a file to ignore to the config", &file)
// fileFlag.FlagShortCut("file", "f")
// folderFlag := ignoreCmd.StringFlag("folder", "tracks all contents of a folder to ignore", &folder)
// folderFlag.FlagShortCut("folder", "fd")
// wildCardFlag := ignoreCmd.StringFlag("wildcard", "treats the input as a wildcard and ignores all files that match the wildcard", &wildcard)
// wildCardFlag.FlagShortCut("wildcard", "wc")
// ignoreCmd.Action(func() error {
// isRepo := validateRepo()
// if !isRepo {
// fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
// os.Exit(0)
// }
// if len(ignoreCmd.OtherArgs()) > 0 {
// ignoreCmd.PrintHelp()
// return fmt.Errorf("incorrect input detected, please fix and retry")
// }
// if file != "" { // if the file flag was used it won't be empty
// //fmt.Println("Ignoring file: ", file)
// err := clientcmd.IgnoreFiles(file, "file", conf)
// if err != nil {
// return err
// }
// return nil
// }
// if folder != "" { // if the folder flag was used it won't be empty
// fmt.Println("Ignoring contents of folder: ", folder)
// err := clientcmd.IgnoreFiles(folder, "folder", conf)
// if err != nil {
// return err
// }
// return nil
// }
// if wildcard != "" { // if the wildcard flag was used it won't be empty
// fmt.Println("Ignoring files with wildcard filter: ", wildcard)
// err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf)
// if err != nil {
// return err
// }
// return nil
// }
// return nil
// })
}

View File

@@ -10,6 +10,10 @@ import (
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
if err != nil {
return err
}
workingDir, err := os.Getwd()
if err != nil {
return err

View File

@@ -2,7 +2,10 @@ package clientcmd
import (
"fmt"
"net"
"os"
"path/filepath"
"strconv"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
@@ -10,6 +13,25 @@ import (
// ConfigPath is the global path to the config that is injected from the main client package.
var ConfigPath string
func validateFileType(path string, inputType string) error {
fullPath, err := filepath.Abs(path)
if err != nil {
return fmt.Errorf("cannot stat file, invalid input? %s", err)
}
fileInfo, err := os.Stat(fullPath)
if err != nil {
return fmt.Errorf("unable to read file, corrupted? %s", err)
}
if fileInfo.IsDir() {
if inputType == "folder" {
return nil
} else {
return fmt.Errorf("folder flag was used, but input is not a folder, will not continue")
}
}
return nil
}
func checkIgnores(input string, inputType string, ignores clientconfig.Ignore) error {
switch inputType {
case "file":
@@ -39,3 +61,24 @@ func checkIgnores(input string, inputType string, ignores clientconfig.Ignore) e
}
return nil
}
// ConnectToServer sends a quick hello to the server to make sure it is live and we can connect to it.
func ConnectToServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) (conn *net.Conn, err error) {
if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch
branchName = "master"
}
for _, remote := range conf.Remotes {
if serverName == remote.Name {
fmt.Printf("Server found in config, connecting to: %s, host: %s, port: %d \n", remote.Name, remote.Host, remote.Port)
port := ":" + strconv.Itoa(remote.Port)
connectionString := remote.Host + port
conn, err := net.Dial("tcp", connectionString)
if err != nil {
return nil, fmt.Errorf("error connecting to %s", connectionString)
}
fmt.Println("Connection started on: ", connectionString)
return &conn, nil
}
}
return nil, fmt.Errorf("unable to find server name in config...")
}

View File

@@ -2,13 +2,109 @@ package clientcmd
import (
"fmt"
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
//IgnoreFiles ignores file(s)/folder based on name/wildcard, etc
func IgnoreFiles(input string, inputType string, ignore clientconfig.Ignore) error {
fmt.Println("File/folder/wildcard to ignore", os.Args[2])
return nil
func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
if err != nil {
return err
}
ignore := conf.Ignores
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkIgnores(input, "file", ignore)
if err != nil {
return fmt.Errorf("%s already ignored: %s", input, err)
}
fmt.Println("Adding file to ignores: ", input)
conf.Ignores.Files = append(conf.Ignores.Files, input)
return nil
case "folder":
err := checkIgnores(input, "folder", ignore)
if err != nil {
return fmt.Errorf("%s is already ignored: %s", input, err)
}
fmt.Println("Adding folder to ignores: ", input)
conf.Ignores.Folders = append(conf.Ignores.Folders, input)
return nil
case "wildcard":
var wildcard string
if input[:1] == "*" { // Removing the wildcard char since we don't store that or test with that char
wildcard = input[1:]
} else {
wildcard = input
}
err := checkIgnores(wildcard, "wildcard", ignore)
if err != nil {
return fmt.Errorf("%s is already ignored: %s", input, err)
}
fmt.Println("Adding wildcard to ignores: ", wildcard)
conf.Ignores.Exts = append(conf.Ignores.Exts, wildcard)
return nil
}
return fmt.Errorf("This... should not have happened, some kind of internal error on IgnoreFiles function call, switch failure")
}
// RemoveIgnoreFiles removes files/folders/wildcards from the ignore list
func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
if err != nil {
return err
}
ignore := conf.Ignores
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkIgnores(input, "file", ignore)
if err != nil {
fmt.Println("Removing file from ignores: ", input)
for i, fileIgnore := range ignore.Files {
if input == fileIgnore {
conf.Ignores.Files[i] = conf.Ignores.Files[len(conf.Ignores.Files)-1] // Deleting the element
conf.Ignores.Files = conf.Ignores.Files[:len(conf.Ignores.Files)-1] // redoing the slice
fmt.Println("Removing file from ignores: ", input)
return nil
}
}
}
fmt.Println("File not found in ingores, unable to remove: ", input)
return nil
case "folder":
err := checkIgnores(input, "folder", ignore)
if err != nil {
for i, folderIgnore := range ignore.Folders {
if input == folderIgnore {
conf.Ignores.Folders[i] = conf.Ignores.Folders[len(conf.Ignores.Folders)-1]
conf.Ignores.Folders = conf.Ignores.Files[:len(conf.Ignores.Folders)-1]
fmt.Println("Removing folder from ignores: ", input)
return nil
}
}
}
fmt.Println("Folder not found in ingores, unable to remove: ", input)
return nil
case "wildcard":
var wildcard string
if input[:1] == "*" { // Removing the wildcard char since we don't store that or test with that char
wildcard = input[1:]
} else {
wildcard = input
}
err := checkIgnores(wildcard, "wildcard", ignore)
if err != nil {
for i, wildcardIgnore := range ignore.Exts {
if input == wildcardIgnore {
conf.Ignores.Exts[i] = conf.Ignores.Exts[len(conf.Ignores.Exts)-1]
conf.Ignores.Exts = conf.Ignores.Exts[:len(conf.Ignores.Exts)-1]
fmt.Println("Removing wildcard from ignores: ", wildcard)
return nil
}
}
}
fmt.Println("Wildcard not found in ingores, unable to remove: ", wildcard)
return nil
}
return fmt.Errorf("This... should not have happened, some kind of internal error on RemoveIgnoreFiles function call, switch failure")
}

27
client/clientcmd/info.go Normal file
View File

@@ -0,0 +1,27 @@
package clientcmd
import (
"bufio"
"fmt"
"net"
"os"
)
func GetServerInfo(conn *net.Conn) error {
for {
fmt.Println("New LOop")
message, err := bufio.NewReader(*conn).ReadString('\n')
if err != nil {
return fmt.Errorf("error reading from connection: %s", err)
}
fmt.Printf("Message from server: %s", message)
switch message {
case "Connected\n":
fmt.Println("Server has acknowledged connection, asking for server details")
conn.Send(fmt.Fprintf(*conn, "Details\n"))
default:
fmt.Println("Details: ", message)
os.Exit(0)
}
}
}

9
server/go.mod Normal file
View File

@@ -0,0 +1,9 @@
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

71
server/go.sum Normal file
View File

@@ -0,0 +1,71 @@
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=

33
server/server.go Normal file
View File

@@ -0,0 +1,33 @@
package main
import (
"fmt"
"github.com/firstrow/tcp_server"
)
var version = "0.1"
func main() {
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")
})
server.OnNewMessage(func(c *tcp_server.Client, message string) {
fmt.Println("new Message from client: ", message)
switch message {
case "Details\n":
fmt.Println("Sending server details to client")
c.Send(fmt.Printf("Server Details are as follows: Version: %s\n", version))
}
})
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
// connection with client lost
})
server.Listen()
}