Golang Context.File Examples

Golang Context.File - 11 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.File extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
File: web.go Project: adriamb/gopad
func doGETCache(c *gin.Context) {

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

	file := store.GetCachePath(hash)
	c.File(file)
}
Example #2
0
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)
	}
}
Example #3
0
File: web.go Project: adriamb/gopad
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)
}
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(),
	})
}
Example #5
0
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)
}
Example #6
0
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)
		}
	}
}