Exemplo n.º 1
0
func serve(conn net.Conn, t lotf.Tail, errch chan<- error) {
	defer conn.Close()
	for s := t.WaitNext(); s != nil; s = t.WaitNext() {
		b := []byte(fmt.Sprintf("%s\n", *s))
		if n, err := conn.Write(b); err != nil {
			glog.Errorf("write error to [%s]: %s", conn.RemoteAddr(), err)
			break
		} else if n != len(b) {
			glog.Infof("could not write at once, writing: %d, written: %d", len(b), n)
		}
	}
}
Exemplo n.º 2
0
func makeJsonRC(t lotf.Tail) *JsonRC {
	l := list.New()
	for {
		if s := t.Next(); s == nil {
			break
		} else {
			l.PushBack(s)
		}
	}

	lines := make([]string, l.Len())
	i := 0
	for e := l.Front(); e != nil; e = e.Next() {
		lines[i] = *(e.Value.(*string))
		i++
	}
	m := &JsonRC{Lines: lines, Error: ""}
	return m
}
Exemplo n.º 3
0
func handleFirst(w http.ResponseWriter, r *http.Request, tail lotf.Tail, name string) {
	uuid, err := cookies.Add(tail.Clone())
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	http.SetCookie(w, &http.Cookie{
		Name:  COOKIE_NAME,
		Value: uuid,
		Path:  cfg.root,
	})
	rc := &TemplateRC{
		Title:    fmt.Sprintf("%s", tail),
		JsonPath: r.URL.Path + NEXT_SUFFIX,
		Expire:   cfg.interval * 1000 / 2,
	}
	if err := templates[name].ExecuteTemplate(w, cfg.lotfs[name].template, rc); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}