github.com/sercand/please@v13.4.0+incompatible/test/workers/worker.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "os" 7 8 "gopkg.in/op/go-logging.v1" 9 ) 10 11 var log = logging.MustGetLogger("worker") 12 13 // A BuildMessage is a minimal subset of BuildRequest / BuildResponse that we use here. 14 // This illustrates one scheme for using it without necessarily requiring the protobufs 15 // (although that is also a valid approach, as javac_worker illustrates). 16 type BuildMessage struct { 17 Rule string `json:"rule"` 18 Success bool `json:"success"` 19 } 20 21 func main() { 22 // Start a web server that we use to communicate with the other tests. 23 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 24 w.Write([]byte("kitten!")) 25 }) 26 go http.ListenAndServe(":31812", nil) 27 28 // Now loop, reading requests forever. 29 // These are just used to indicate that we're ready to receive a new test. 30 decoder := json.NewDecoder(os.Stdin) 31 encoder := json.NewEncoder(os.Stdout) 32 for { 33 msg := &BuildMessage{} 34 if err := decoder.Decode(msg); err != nil { 35 log.Fatalf("Failed to decode input: %s", err) 36 } 37 msg.Success = true 38 if err := encoder.Encode(msg); err != nil { 39 log.Fatalf("Failed to encode output: %s", err) 40 } 41 } 42 }