3 回答

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
紐約時(shí)報(bào)已經(jīng)發(fā)布了用于Go的gzip中間件軟件包。
您只要http.HandlerFunc通過(guò)他們的操作GzipHandler,您就完成了??雌饋?lái)像這樣:
package main
import (
"io"
"net/http"
"github.com/nytimes/gziphandler"
)
func main() {
withoutGz := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
io.WriteString(w, "Hello, World")
})
withGz := gziphandler.GzipHandler(withoutGz)
http.Handle("/", withGz)
http.ListenAndServe("0.0.0.0:8000", nil)
}
- 3 回答
- 0 關(guān)注
- 223 瀏覽
添加回答
舉報(bào)