本文整理匯總了Golang中github.com/gin-gonic/gin.Context.File方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.File方法的具體用法?Golang Context.File怎麽用?Golang Context.File使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.File方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConvertRaw
func (tr *TemplatesResource) ConvertRaw(c *gin.Context) {
var (
err error
job conv.Job
res conv.Result
buf = []byte{}
)
if buf, err = ioutil.ReadAll(c.Request.Body); err != nil {
log.Printf("Error while reading body: %s", err)
c.JSON(500, ErrInternal)
return
}
job = createRawJob(string(buf))
tr.jobsChan <- job
res = <-job.ResultChan
if res.Error == nil {
c.File(res.ResultPath)
} else {
log.Printf("Error while converting: %s", res.Error)
c.JSON(500, ErrInternal)
}
}
示例2: doGETFile
func doGETFile(c *gin.Context) {
ID := normalize(c.Param("id"))
ws := normalize(c.Param("ws"))
name := normalize(c.Param("name"))
file := instance.Srv.Store.Entry.FilePath(ws, ID, name)
c.File(file)
}
示例3: certHandler
func certHandler(c *gin.Context) {
if strings.Contains(c.Request.UserAgent(), "Firefox") {
c.Header("content-type", "application/x-x509-ca-cert")
c.File("ca.cert.cer")
return
}
noFirefoxTemplate.Execute(c.Writer, gin.H{
"url": "http://" + c.Request.Host + c.Request.URL.String(),
})
}
示例4: handleResize
func handleResize(c *gin.Context) {
size, err := strconv.ParseInt(c.Query("size"), 10, 0)
resp, err := http.Get(c.Query("img"))
if err != nil {
panic(err)
}
imgName := createImageFromResponse(resp)
resizedImg := resizeImage(imgName, int(size))
c.File(resizedImg)
}
示例5: Convert
func (tr *TemplatesResource) Convert(c *gin.Context) {
var (
id = GetIdParam(c)
res conv.Result
job conv.Job
tmpl models.Template
buf []byte
data map[string]interface{}
err error
)
if tr.db.First(&tmpl, id).RecordNotFound() {
c.JSON(404, ErrNotFound)
} else {
if buf, err = ioutil.ReadAll(c.Request.Body); err != nil {
log.Printf("Error while reading body: %s", err)
c.JSON(500, ErrInternal)
return
}
// Only try to parse json if the body has actual content
if len(buf) > 0 {
if err := json.Unmarshal(buf, &data); err != nil {
c.JSON(400, ErrInvalidJson)
return
}
}
job = conv.Job{
Template: tmpl,
Data: data,
ResultChan: make(conv.ResultChan),
}
tr.jobsChan <- job
res = <-job.ResultChan
if res.Error == nil {
c.File(res.ResultPath)
} else {
log.Printf("Error while converting: %s", res.Error)
c.JSON(500, ErrInternal)
}
}
}
示例6: handleStatic
func (s *Server) handleStatic(c *gin.Context) {
var ct string
// Get static file path
p, _ := c.Params.Get("path")
if p == "" {
p = "index.html"
}
// Try to get file data from filesystem
localPath := path.Join(s.config.StaticDir, p)
if _, err := os.Stat(localPath); err == nil {
logger.Debug("server", "serving %q from filesystem", p)
c.File(localPath)
return
}
// Get file data from built-in assets
data, err := Asset(strings.TrimPrefix(p, "/"))
if err != nil {
c.JSON(http.StatusNotFound, nil)
return
}
switch path.Ext(p) {
case ".css":
ct = "text/css"
case ".js":
ct = "text/javascript"
default:
ct = http.DetectContentType(data)
}
logger.Debug("server", "serving %q from built-in assets", p)
c.Data(http.StatusOK, ct, data)
}
示例7: Index
func Index(c *gin.Context) {
c.File("./templates/index.html")
}
示例8: handle404
func handle404(c *gin.Context) {
c.File("./client/templates/404.html")
}
示例9: ServeRepoFile
func ServeRepoFile(c *gin.Context) {
repo := session.Repo(c)
arch := c.Param("arch")
file := c.Param("file")
c.File(path.Join(repo.PathDeep(arch), file))
}
示例10: IndexHandler
func IndexHandler(c *gin.Context) {
c.File("static/index.html")
}
示例11: doGETCache
func doGETCache(c *gin.Context) {
hash := normalize(c.Param("hash"))
file := store.GetCachePath(hash)
c.File(file)
}