<commit_before>package web

import (
	"doozer/store"
	"doozer/util"
	"http"
	"io"
	"json"
	"log"
	"net"
	"runtime"
	"strings"
	"template"
	"websocket"
)

var Store *store.Store
var ClusterName, evPrefix string

var (
	mainTpl  = template.MustParse(main_html, nil)
	statsTpl = template.MustParse(stats_html, nil)
)

type info struct {
	Path string
}

type stringHandler struct {
	contentType string
	body        string
}

func (sh stringHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.SetHeader("content-type", sh.contentType)
	io.WriteString(w, sh.body)
}

func Serve(listener net.Listener) {
	prefix := "/d/" + ClusterName
	evPrefix = "/events" + prefix

	http.Handle("/", http.RedirectHandler("/view/d/"+ClusterName+"/", 307))
	http.HandleFunc("/stats.html", statsHtml)
	http.HandleFunc("/view/", viewHtml)
	http.Handle("/main.js", stringHandler{"application/javascript", main_js})
	http.Handle("/main.css", stringHandler{"text/css", main_css})
	http.HandleFunc(evPrefix+"/", evServer)

	http.Serve(listener, nil)
}

func send(ws *websocket.Conn, path string, evs <-chan store.Event, logger *log.Logger) {
	defer close(evs)
	l := len(path) - 1
	for ev := range evs {
		ev.Getter = nil // don't marshal the entire snapshot
		ev.Path = ev.Path[l:]
		logger.Println("sending", ev)
		b, err := json.Marshal(ev)
		if err != nil {
			logger.Println(err)
			return<commit_msg>web: don't close the event chan<commit_after>package web

import (
	"doozer/store"
	"doozer/util"
	"http"
	"io"
	"json"
	"log"
	"net"
	"runtime"
	"strings"
	"template"
	"websocket"
)

var Store *store.Store
var ClusterName, evPrefix string

var (
	mainTpl  = template.MustParse(main_html, nil)
	statsTpl = template.MustParse(stats_html, nil)
)

type info struct {
	Path string
}

type stringHandler struct {
	contentType string
	body        string
}

func (sh stringHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.SetHeader("content-type", sh.contentType)
	io.WriteString(w, sh.body)
}

func Serve(listener net.Listener) {
	prefix := "/d/" + ClusterName
	evPrefix = "/events" + prefix

	http.Handle("/", http.RedirectHandler("/view/d/"+ClusterName+"/", 307))
	http.HandleFunc("/stats.html", statsHtml)
	http.HandleFunc("/view/", viewHtml)
	http.Handle("/main.js", stringHandler{"application/javascript", main_js})
	http.Handle("/main.css", stringHandler{"text/css", main_css})
	http.HandleFunc(evPrefix+"/", evServer)

	http.Serve(listener, nil)
}

func send(ws *websocket.Conn, path string, evs <-chan store.Event, logger *log.Logger) {
	l := len(path) - 1
	for ev := range evs {
		ev.Getter = nil // don't marshal the entire snapshot
		ev.Path = ev.Path[l:]
		logger.Println("sending", ev)
		b, err := json.Marshal(ev)
		if err != nil {
			logger.Println(err)
			return
{'fraction_non_alphanumeric': 0.15645277577505406, 'fraction_numerical': 0.002883922134102379, 'mean_word_length': 4.305927342256214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2085381', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1005, 'n_words': 232}