Skip to content

Instantly share code, notes, and snippets.

@acoshift

acoshift/main.go Secret

Created July 7, 2017 16:05
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/2a92b9cc49f6dfd88ef3c44417af267a to your computer and use it in GitHub Desktop.
Save acoshift/2a92b9cc49f6dfd88ef3c44417af267a to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"html/template"
"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) {
buf := bytes.Buffer{}
t.Execute(&buf, nil)
m.Minify("text/html", w, &buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment