-
-
Save acoshift/2a92b9cc49f6dfd88ef3c44417af267a 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 ( | |
"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