gin从reader读取数据
Posted chenguifeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gin从reader读取数据相关的知识,希望对你有一定的参考价值。
1 package main 2 3 import ( 4 "net/http" 5 "github.com/gin-gonic/gin" 6 ) 7 8 func main() { 9 r := gin.Default() 10 11 r.GET("/someDataFromReader", func(c *gin.Context) { 12 response, err := http.Get("https://raw.githubusercontent.com/gin-gonic/logo/master/color.png") 13 if err != nil || response.StatusCode != http.StatusOK { 14 c.Status(http.StatusServiceUnavailable) 15 return 16 } 17 18 reader := response.Body 19 contentLength := response.ContentLength 20 contentType := response.Header.Get("Content-Type") 21 22 extraHeaders := map[string]string { 23 "Content-Disposition": `attachment; filename="goher.png"`, 24 } 25 c.DataFromReader(http.StatusOK, contentLength, contentType, reader, extraHeaders) 26 }) 27 r.Run(":8080") 28 }
以上是关于gin从reader读取数据的主要内容,如果未能解决你的问题,请参考以下文章