예제 #1
0
// 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)
		}
	}
}
예제 #2
0
파일: main.go 프로젝트: jeffbr13/diff-mail
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.")
}