381 Star 2.5K Fork 616

GVPJohn / gf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
download.go 660 Bytes
一键复制 编辑 原始数据 按行查看 历史
John 提交于 2018-11-11 13:55 . 增加ghttp下载文件示例
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
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)
s.Run()
}
Go
1
https://gitee.com/johng/gf.git
git@gitee.com:johng/gf.git
johng
gf
gf
v1.4.7

搜索帮助

53164aa7 5694891 3bd8fe86 5694891