Beispiel #1
0
// binds an event source to a packet type (ie TCP)
// creates an http handler to allow subscription to the packet type
func (sm SourceMap) Add(label string) es.EventSource {
	c := Source{
		es:    es.New(nil),
		label: label,
		url:   "/pcap/" + label + "/"}
	sm[label] = c
	return c.es
}
Beispiel #2
0
func New() eventsource.EventSource {
	Src = eventsource.New(eventsource.DefaultSettings(), func(req *http.Request) [][]byte {
		return [][]byte{
			[]byte("X-Accel-Buffering: no"),
			[]byte("Access-Control-Allow-Origin: " + req.Header.Get("Origin")),
			[]byte("Access-Control-Allow-Credentials: true"),
		}
	})
	return Src
}
Beispiel #3
0
func handleEventSource(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Handle event source: ", r.URL.Path)
	// create a new connection for the event source action
	clientId := strings.Split(r.URL.Path, "/")[2]
	fmt.Println("clientID: ", clientId)
	es := eventsource.New(nil, nil)
	c := &Connection{send: make(chan []byte, 256), es: es, isWebsocket: false}
	// TODO: NEED TO ASSOCIATED THE EXISTING FAYE CLIENT INFO/SUBSCRIPTIONS WITH THE CONNECTION CHANNEL
	// USE CLIENT ID TO UPDATE FAYE INFO WITH ES CONNETION CHANNEL
	f.UpdateClientChannel(clientId, c.send)
	go c.esWriter(f)
	c.es.ServeHTTP(w, r)
	return
}
Beispiel #4
0
func (sc *chanCollection) newChannel(id string) {
	log.Printf("creating channel %s", id)

	pubsub, err := sc.redisClient.PubSubClient()
	if err != nil {
		panic(err)
	}

	redisCh, err := pubsub.PSubscribe(id)
	if err != nil {
		panic(err)
	}

	es := eventsource.New(nil)
	s := channel{pubsub, es, redisCh, id, false}
	sc.channels[id] = s
}
Beispiel #5
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Elasticsearch
	api.Domain = "localhost"

	// Proxy
	go doTheProxyStuff()

	// HTTP
	es := eventsource.New(nil)
	defer es.Close()
	go DispatchLogs(es)
	http.Handle("/events", es)

	m := pat.New()
	m.Get("/logs", http.HandlerFunc(PrintLogs))
	m.Get("/logs/:logid", http.HandlerFunc(PrintLog))
	//m.Get("/logs/?filter=:ip", http.HandlerFunc(PrintLogsForIp))
	http.Handle("/", m)
	http.ListenAndServe("0.0.0.0:8081", nil)
}