// start accepting connections and consume each of them as they come in func (h *HTTPProvider) Start(p event.EventPasser) { defer func() { if r := recover(); r != nil { fmt.Println("Recovered in f", r) } }() std_http.HandleFunc(ENDPOINT, func(w std_http.ResponseWriter, r *std_http.Request) { // handle the case where a provider is restarting and needs to check if a listener is a bangarang provider or not if r.URL.Query().Get("init_check") == "true" { w.Write([]byte(START_HANDSHAKE)) } buff, err := ioutil.ReadAll(r.Body) if err != nil { logrus.Error(err) std_http.Error(w, err.Error(), std_http.StatusInternalServerError) return } e := &event.Event{} err = h.pool.Decode(buff, e) if err != nil { logrus.Error(err) std_http.Error(w, err.Error(), std_http.StatusInternalServerError) return } p.PassEvent(e) logrus.Debug("Done processing http event") }) logrus.Infof("Serving http listener on %s", h.listen) logrus.Fatal(std_http.ListenAndServe(h.listen, nil)) }
func (t *TCPProvider) consume(c *net.TCPConn, p event.EventPasser) { // create a newman connection conn := newman.NewConn(c) conn.SetWaiter(&newman.Backoff{}) // drain the connection for ever in, _ := conn.Generate(func() newman.Message { return event.NewEvent() }) for raw := range in { // convert it to an event because we know that is what we are getting e := raw.(*event.Event) // pass it on to the next step p.PassEvent(e) } // when it is done, close the connection c.Close() }