當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.File方法代碼示例

本文整理匯總了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)
	}
}
開發者ID:vongruenigen,項目名稱:gendok,代碼行數:25,代碼來源:templates.go

示例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)
}
開發者ID:adriamb,項目名稱:gopad,代碼行數:9,代碼來源:web.go

示例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(),
	})
}
開發者ID:brunodisilva,項目名稱:arduino-create-agent,代碼行數:10,代碼來源:certificates.go

示例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)
}
開發者ID:Daio-io,項目名稱:pic-sizer,代碼行數:12,代碼來源:main.go

示例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)
		}
	}
}
開發者ID:vongruenigen,項目名稱:gendok,代碼行數:45,代碼來源:templates.go

示例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)
}
開發者ID:vbatoufflet,項目名稱:goverview,代碼行數:38,代碼來源:static.go

示例7: Index

func Index(c *gin.Context) {
	c.File("./templates/index.html")
}
開發者ID:serkas,項目名稱:knots,代碼行數:3,代碼來源:staticHandlers.go

示例8: handle404

func handle404(c *gin.Context) {
	c.File("./client/templates/404.html")
}
開發者ID:01AutoMonkey,項目名稱:gin-webapp-init,代碼行數:3,代碼來源:server.go

示例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))
}
開發者ID:mikkeloscar,項目名稱:maze,代碼行數:6,代碼來源:repo.go

示例10: IndexHandler

func IndexHandler(c *gin.Context) {
	c.File("static/index.html")
}
開發者ID:sdvdxl,項目名稱:gin-extend,代碼行數:3,代碼來源:index.go

示例11: doGETCache

func doGETCache(c *gin.Context) {

	hash := normalize(c.Param("hash"))

	file := store.GetCachePath(hash)
	c.File(file)
}
開發者ID:adriamb,項目名稱:gopad,代碼行數:7,代碼來源:web.go


注:本文中的github.com/gin-gonic/gin.Context.File方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。