lundi 3 octobre 2016

how to gzip a template in golang web

I have already set the value of contest-encoding, but how can I gzip the template, since the file is still to big.

func indexPageHandler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Encoding", "gzip")
    tmpl, err := template.New("index.html").ParseGlob("./templates/*")
    if err != nil {
        log.Println(err)
        return
    }   
    err = tmpl.Execute(w, nil)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }   
}

Is there any function that can gzip the response?




Aucun commentaire:

Enregistrer un commentaire