starting client/server connection
This commit is contained in:
@@ -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...")
|
||||
}
|
||||
|
Reference in New Issue
Block a user