implements very basic getting of input and sending them as commands to the server and printing responses
2 files changed, 38 insertions(+), 12 deletions(-)

M gorcon/client.go
M main.go
M gorcon/client.go +17 -5
@@ 38,17 38,21 @@ func NewClient(addr string) (c *Client, 
     return
 }
 
-func (c *Client) Auth(data string) (chan error) {
+func (c *Client) Auth(data string) (<-chan error) {
     _, errch := c.writeCommand(AUTH_ID, SERVERDATA_AUTH, []byte(data))
     return errch
 }
 
-func (c *Client) writeCommand(id int32, cmdtype CmdType, body []byte) (chan *Message, chan error) {
+func (c *Client) Exec(data string) (<-chan *Message, <-chan error) {
+    return c.writeCommand(EXEC_ID, SERVERDATA_EXECCOMMAND, []byte(data))
+}
+
+func (c *Client) writeCommand(id int32, cmdtype CmdType, body []byte) (<-chan *Message, <-chan error) {
     msgch := make(chan *Message, 1) // Keep these async
     errch := make(chan error, 1)
     if err := writeCommand(c, id, cmdtype, body); err != nil {
         errch <- err
-        close(msgch)
+        //close(msgch)
     } else {
         c.queue.Push(&comm{msgch, errch})
     }

          
@@ 81,7 85,7 @@ func (c *Client) readLoop() {
             } else {
                 comm.errch <- fmt.Errorf("Authentication Failed")
             }
-            close(comm.msgch)
+            //close(comm.msgch)
         } else if resp.Id == AUTH_ID && resp.Type == SERVERDATA_RESPONSE_VALUE {
             // Packet one of two of response to auth request
             log.Println("Received one of two of responses to auth request")

          
@@ 90,7 94,7 @@ func (c *Client) readLoop() {
             log.Println("Received response to exec request")
             c.queue.Pop()
             comm.msgch <- &Message{[]*packet{resp}}
-            close(comm.errch)
+            //close(comm.errch)
         } else {
             log.Println("Received ... fuck if I know ... I'm likely going to crash and burn!")
             c.queue.Pop()

          
@@ 100,10 104,18 @@ func (c *Client) readLoop() {
 
 ////////////////////////////////////////////////////////////////////////////////
 
+// This needs help ...
 type Message struct {
     packets []*packet
 }
 
+func (m *Message) AllText() (s string) {
+    for _, p := range m.packets {
+        s += string(p.Body)
+    }
+    return
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 type comm struct {

          
M main.go +21 -7
@@ 1,5 1,6 @@ 
 package main
 
+import "bufio"
 import "flag"
 import "fmt"
 import "log"

          
@@ 33,6 34,7 @@ func main() {
     if err != nil {
         log.Panicln(err)
     }
+    defer client.Close()
 
     log.Println("Connected to server")
 

          
@@ 41,17 43,29 @@ func main() {
     case err := <-errch:
         if err != nil {
             log.Println(err)
+            return
         } else {
-            log.Println("success?")
+            log.Println("success!")
         }
     }
 
-    //select {
-    //case msg := <-msgch:
-    //    log.Println(msg)
-    //case err := <-errch:
-    //    log.Panicln(err)
-    //}
+
+    scanner := bufio.NewScanner(os.Stdin)
+    for {
+        fmt.Printf("> ")
+        if false == scanner.Scan() {
+            break
+        }
+        inp := scanner.Text()
+        msgch, errch := client.Exec(inp)
+        select {
+        case msg := <-msgch:
+            log.Println(msg)
+            log.Print(string(msg.AllText()))
+        case err := <-errch:
+            log.Panicln(err)
+        }
+    }
 
     log.Println("done...")
 }