improving client/server info command

This commit is contained in:
2020-06-07 18:31:01 -04:00
parent dd3fd7c4ae
commit 6d738b138d
12 changed files with 72 additions and 31 deletions

View File

@@ -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")
}

View File

@@ -6,18 +6,24 @@ import (
"github.com/go-resty/resty/v2"
)
// GetServerInfo queries the supplied server name for information about the current repo from the server
func GetServerInfo() error {
serverURL := "http://localhost:80/info/"
// GetServerInfo queries the supplied connection string for server info and uses the provided repoName to get repo specific information
func GetServerInfo(connectionString string, repoName string) error {
serverURL := connectionString + "/info/" //creating the full string to get info
client := resty.New()
resp, err := client.R().
SetPathParams(map[string]string{
"repoName": "testRepo",
"repoName": repoName,
}).
Get(serverURL + "{repoName}")
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", serverURL, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
return nil
}

View File

@@ -4,10 +4,11 @@ import (
"fmt"
"log"
"os"
"path/filepath"
)
// InitializeRepo creates the repo directory and a new config file
func InitializeRepo() {
func InitializeRepo() string {
cwd, err := os.Getwd()
if err != nil {
log.Fatal("unable to get current working directory.. permissions issue?")
@@ -17,4 +18,7 @@ func InitializeRepo() {
if err != nil {
fmt.Println(".gvc directory already exists, but no config file... continuing")
}
repoName := filepath.Base(cwd)
fmt.Println("Adding new repo with name: ", repoName)
return repoName
}

View File

@@ -1,6 +1,8 @@
package clientcmd
import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
@@ -9,10 +11,11 @@ func RefreshContent(conf *clientconfig.Gvcconfig) error {
remotes := conf.Remotes
for _, remote := range remotes {
if remote.Default {
err := PingServer(remote.Name, conf.CurrentBranch, conf)
connectionString, err := FindServer(remote.Name, conf.CurrentBranch, conf)
if err != nil {
return err
}
fmt.Println("Connection String; ", connectionString) //TODO: Remove not needed
//TODO: Now refresh content
}
}