Merge branch 'spec-update' into 'master'

Spec update

Rebase of the updates to comply with the new spec.

See merge request !9
This commit is contained in:
Ian Adam Naval 2014-10-16 19:19:22 -04:00
commit facd7aa6d7

View File

@ -5,6 +5,7 @@ package jsh
import (
"encoding/json"
"fmt"
"os"
)
type JshFrame struct {
@ -22,22 +23,44 @@ func (j JshFrame) ToJson() *string {
return &jsonString
}
func (j JshFrame) StdOutToJson() *string {
jsonOut, err := json.Marshal(j.StdOut)
if err != nil {
panic(err)
}
jsonString := string(jsonOut)
return &jsonString
}
func (j JshFrame) StdErrToJson() *string {
jsonOut, err := json.Marshal(j.StdErr)
if err != nil {
panic(err)
}
jsonString := string(jsonOut)
return &jsonString
}
// goroutine for outputing frames. Pass it a channel of pointers to JshFrames,
// and it will send "true" to the done channel once you close the queue channel.
func OutputFrames(queue chan *JshFrame, done chan bool) {
fmt.Printf("[")
fmt.Fprintf(os.Stderr, "[")
isFirst := true
for {
frame, more := <-queue
if more {
if !isFirst {
fmt.Printf(",")
fmt.Fprintf(os.Stderr, ",")
} else {
isFirst = false
}
fmt.Printf(*frame.ToJson())
fmt.Printf(*frame.StdOutToJson())
fmt.Fprintf(os.Stderr, *frame.StdErrToJson())
} else {
fmt.Printf("]\n")
fmt.Fprintf(os.Stderr, "]\n")
done <- true
return
}