-
-
Save acoshift/9eca8c592cb050112176eb4566238a15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"html/template" | |
"io" | |
"net/http" | |
"github.com/tdewolff/minify" | |
"github.com/tdewolff/minify/html" | |
) | |
var ( | |
m = minify.New() | |
t = template.Must(template.ParseFiles("index.tmpl")) | |
) | |
func main() { | |
m.AddFunc("text/html", html.Minify) | |
http.HandleFunc("/", indexHandler) | |
http.ListenAndServe(":8080", nil) | |
} | |
func indexHandler(w http.ResponseWriter, r *http.Request) { | |
pr, pw := io.Pipe() | |
go func() { | |
pw.CloseWithError(t.Execute(pw, nil)) | |
}() | |
m.Minify("text/html", w, pr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment