func handleHTTP(c ntm.Controller, losses []float64, doPrint *bool) { select { case cn := <-weightsChan: b, err := json.Marshal(c.WeightsVal()) if err != nil { log.Fatalf("%v", err) } cn <- b case cn := <-lossChan: cn <- losses case <-printDebugChan: *doPrint = !*doPrint default: return } }
func assignWeights(c ntm.Controller) { if *weightsFile == "" { flag.PrintDefaults() os.Exit(1) } f, err := os.Open(*weightsFile) if err != nil { log.Fatalf("%v", err) } defer f.Close() ws := c.WeightsVal() if err := json.NewDecoder(f).Decode(&ws); err != nil { log.Fatalf("%v", err) } }