package mainimport ("fmt""log""net/http""github.com/gin-gonic/gin")func main() {engine := gin.Default()//8Mengine.MaxMultipartMemory = 8 << 20engine.POST("/upload", func(c *gin.Context) {file, err := c.FormFile("file")if err != nil {log.Println(err)c.String(h...
这里的关键点在于gin.Dir函数的第二个参数,true代表可以列目录的意思。 代码语言:javascript 代码运行次数:0 运行 AI代码解释 // if listDirectory == true, then it works the same as http.Dir() otherwise it returns// a filesystem that prevents http.FileServer() to list the directory files.funcDir...
$ go tool pprof http://127.0.0.1:6060/debug/pprof/profile?seconds=30Saved profilein/root/pprof/pprof.demo.samples.CPU.001.pb.gzFile:demoType:CPUTime:Dec24,2023at11:42am(CST)Duration:10s,Total samples=70ms(0.7%)Entering interactivemode(type"help"forcommands,"o"foroptions)(pprof) 1.1.2 ...
returnfile_header, read_data[file_head_loc+4:read_total],nil } returnfile_header,nil,fmt.Errorf("reach to sream EOF") } funcmain(){ log.SetFlags(log.LstdFlags | log.Lshortfile) r := gin.Default() r.StaticFile("/upload.html","./upload.html") r.POST("/gin_upload",func(c *g...
golang gin框架中实现大文件的流式上传 一般来说,通过c.Request.FormFile()获取文件的时候,所有内容都全部读到了内存。如果是个巨大的文件,则可能内存会爆掉;且,有的时候我们需要一边上传一边处理。 以下的代码实现了大文件流式上传。 还非常不完美,但是可以作为参考: ...
之前利用空闲时间做了一个个人博客系统,后端主要使用golang+gin框架+Mysql实现,前端使用vue+element ui + bootstrap。项目的部署使用docker,nginx作为静态资源服务器和反向代理服务器。 结构图如下: 1、效果图 访问地址:我的博客博客首页: 博客详情页 文章标签 ...
1.1 Gin 的背景 Gin 是 Golang 世界里最流行的 web 框架,于 github 开源:https://github.com/...
import ( "fmt" "gin_hello/gb" "/gin-gonic/gin" "io" "os" ) func main() { r := gin.New() r.Use(gin.Recovery()) //1.日志输出到文件,文件所在位置 f,_ := os.OpenFile("./app01.log",os.O_CREATE|os.O_APPEND|os.O_RDWR,0644) //配置中间件 //r.Use(gin.LoggerWithWriter(...
funcmain(){router:=gin.Default()router.StaticFile("/adobegc.log","/tmp/adobegc.log")router.Run(":8080")} 通过StaticFile方法,把文件/tmp/adobegc.log托管在网络上,并且设置访问路径为/adobegc.log,这样我们通过http://localhost:8080/adobegc.log就可以访问这个文件,看到它的内容了。
golanggin框架中实现⼤⽂件的流式上传 ⼀般来说,通过c.Request.FormFile()获取⽂件的时候,所有内容都全部读到了内存。如果是个巨⼤的⽂件,则可能内存会爆掉;且,有的时候我们需要⼀边上传⼀边处理。以下的代码实现了⼤⽂件流式上传。还⾮常不完美,但是可以作为参考:upload.html <!