improving client/server info command
This commit is contained in:
		@@ -7,7 +7,6 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
 | 
			
		||||
	clientconfig "github.com/deranjer/gvc/client/clientconfig"
 | 
			
		||||
	"github.com/go-resty/resty/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ConfigPath is the global path to the config that is injected from the main client package.
 | 
			
		||||
@@ -62,8 +61,8 @@ func checkFileTypes(input string, inputType string, ignores clientconfig.FileTyp
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PingServer sends a quick hello to the server to make sure it is live and we can connect to it. //TODO Remove this is just extra shit
 | 
			
		||||
func PingServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) error {
 | 
			
		||||
// FindServer finds the supplied server connection settings, creates a connection string and returns it
 | 
			
		||||
func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) (connectionString string, err error) {
 | 
			
		||||
	if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch
 | 
			
		||||
		branchName = "master"
 | 
			
		||||
	}
 | 
			
		||||
@@ -71,19 +70,10 @@ func PingServer(serverName string, branchName string, conf *clientconfig.Gvcconf
 | 
			
		||||
		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 := "http://" + remote.Host + port + "/hello" //Create our hello request
 | 
			
		||||
			fmt.Println("Attempting connection on: ", connectionString)
 | 
			
		||||
			client := resty.New()
 | 
			
		||||
 | 
			
		||||
			resp, err := client.R().EnableTrace().Get(connectionString)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
 | 
			
		||||
			}
 | 
			
		||||
			if resp.StatusCode() == 200 {
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
			return fmt.Errorf("response from server was not 200, was instead %d", resp.StatusCode())
 | 
			
		||||
			connectionString := "http://" + remote.Host + port //Create our connection string
 | 
			
		||||
			fmt.Println("Generated connection string: ", connectionString)
 | 
			
		||||
			return connectionString, nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return fmt.Errorf("unable to find server name in config")
 | 
			
		||||
	return "", fmt.Errorf("unable to find server name in config")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user