// diffHandler returns an http.HandlerFunc that serves the diff of the // two given files. func diffHandler(filename1, filename2 string) http.HandlerFunc { diff := difflib.HTMLDiff(fileToLines(filename1), fileToLines(filename2)) tmpl, _ := template.New("diffTemplate").Parse(templateString) return func(w http.ResponseWriter, r *http.Request) { err := tmpl.Execute(w, map[string]interface{}{ "Diff": template.HTML(diff), "Filename1": filename1, "Filename2": filename2, }) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } }
func (store *scrapeStore) htmlDiffPrev() (string, error) { if store.prev() != nil { return "<table>" + difflib.HTMLDiff(bytesToStringsOnNewline(store.prev()), bytesToStringsOnNewline(store.current())) + "</html>", nil } return "", fmt.Errorf("Can't generate diff with only one scrape.") }