basic server/client http communication setup
This commit is contained in:
		@@ -1,43 +1,19 @@
 | 
			
		||||
package clientcmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	clientconfig "github.com/deranjer/gvc/client/clientconfig"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
 | 
			
		||||
func RefreshContent(conf *clientconfig.Gvcconfig) error {
 | 
			
		||||
	remotes := conf.Remotes
 | 
			
		||||
	for _, remote := range remotes {
 | 
			
		||||
		if remote.Default {
 | 
			
		||||
			conn, err := ConnectToServer(remote.Name, conf.CurrentBranch, conf)
 | 
			
		||||
			err := PingServer(remote.Name, conf.CurrentBranch, conf)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			for { // Server should send 'Connected\n' to client after connect, then client can ask for server details
 | 
			
		||||
				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")
 | 
			
		||||
					bytesSent, err := fmt.Fprintf(*conn, "Details\n")
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						fmt.Println("Error sending message to server! ", err)
 | 
			
		||||
						os.Exit(0)
 | 
			
		||||
					}
 | 
			
		||||
					if bytesSent > 0 {
 | 
			
		||||
						fmt.Println("Message Sent")
 | 
			
		||||
					}
 | 
			
		||||
				default:
 | 
			
		||||
					fmt.Println("Details: ", message)
 | 
			
		||||
					os.Exit(0)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			//TODO: Now refresh content
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user