增加ghttp下载文件示例

This commit is contained in:
John
2018-11-11 13:55:32 +08:00
parent 6ff44ad123
commit b303bf12b5

View File

@ -8,6 +8,11 @@ import (
func main() {
s := g.Server()
s.BindHandler("/download", func(r *ghttp.Request){
r.Response.Header().Set("Content-Type", "text/html;charset=utf-8");
r.Response.Header().Set("Content-type", "application/force-download");
r.Response.Header().Set("Content-Type", "application/octet-stream");
r.Response.Header().Set("Accept-Ranges", "bytes");
r.Response.Header().Set("Content-Disposition", "attachment;filename=\"下载文件名称.txt\"");
r.Response.ServeFile("text.txt")
})
s.SetPort(8199)