Skip to content

Instantly share code, notes, and snippets.

@acoshift

acoshift/main.go Secret

Created July 7, 2017 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoshift/9eca8c592cb050112176eb4566238a15 to your computer and use it in GitHub Desktop.
Save acoshift/9eca8c592cb050112176eb4566238a15 to your computer and use it in GitHub Desktop.
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