• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang revel.Response类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/revel/revel.Response的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Response类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Apply

func (r *StaticBinaryResult) Apply(req *revel.Request, resp *revel.Response) {
	// If we have a ReadSeeker, delegate to http.ServeContent
	if rs, ok := r.Reader.(io.ReadSeeker); ok {
		// http.ServeContent doesn't know about response.ContentType, so we set the respective header.
		if resp.ContentType != "" {
			resp.Out.Header().Set("Content-Type", resp.ContentType)
		} else {
			contentType := revel.ContentTypeByFilename(r.Name)
			resp.Out.Header().Set("Content-Type", contentType)
		}
		http.ServeContent(resp.Out, req.Request, r.Name, r.ModTime, rs)
	} else {
		// Else, do a simple io.Copy.
		if r.Length != -1 {
			resp.Out.Header().Set("Content-Length", strconv.FormatInt(r.Length, 10))
		}
		resp.WriteHeader(http.StatusOK, revel.ContentTypeByFilename(r.Name))
		io.Copy(resp.Out, r.Reader)
	}

	// Close the Reader if we can
	if v, ok := r.Reader.(io.Closer); ok {
		v.Close()
	}
}
开发者ID:bertzzie,项目名称:obrolansubuh-module,代码行数:25,代码来源:static.go


示例2: Apply

func (r *ConvertResult) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")

	resp.Out.Write([]byte("<pre><code>\n"))

	logger := func(line string) {
		resp.Out.Write([]byte(line + "\n"))

		if revel.DevMode {
			fmt.Println(line)
		}

		if f, ok := resp.Out.(http.Flusher); ok {
			f.Flush()
		}
	}

	shortUrl, err := models.Convert(r.url, r.koofr, logger)

	if err != nil {
		revel.ERROR.Println(err)
		return
	}

	resp.Out.Write([]byte("</pre></code>\n"))

	resp.Out.Write([]byte("<br /><a href=\"" + shortUrl + "\">" + shortUrl + "</a>"))

	return
}
开发者ID:bancek,项目名称:youtube-to-koofr,代码行数:30,代码来源:app.go


示例3: Apply

func (r jsonApiRES) Apply(req *revel.Request, resp *revel.Response) {

	resp.WriteHeader(http.StatusOK, "application/vnd.api+json")

	if err := jsonapi.MarshalManyPayload(resp.Out, r); err != nil {
		http.Error(resp.Out, err.Error(), 500)
	}

}
开发者ID:rishirajdev,项目名称:RestAPI-revel,代码行数:9,代码来源:users.go


示例4: Apply

func (c CommonResult) Apply(req *revel.Request, resp *revel.Response) {
	if c.Code == 0 {
		c.Code = 200
	}
	if len(c.ContentType) == 0 {
		c.ContentType = ContentTypeHTML
	}
	resp.WriteHeader(c.Code, c.ContentType)
	resp.Out.Write(c.Data)
}
开发者ID:wangboo,项目名称:gutil,代码行数:10,代码来源:asset.go


示例5: Apply

func (r JsonErrorResult) Apply(req *revel.Request, resp *revel.Response) {
	var b []byte
	resultJson := JsonError{Error: r.ErrorMessage}

	b, err := json.Marshal(resultJson)

	if err != nil {
		revel.ErrorResult{Error: err}.Apply(req, resp)
		return
	}

	resp.WriteHeader(r.StatusCode, "application/json; charset=utf-8")
	resp.Out.Write(b)
}
开发者ID:oblank,项目名称:rozklad_cdtu,代码行数:14,代码来源:custom_responses.go


示例6: render

func (r *RenderTemplateResult) render(req *revel.Request, resp *revel.Response, wr io.Writer) {
	err := r.Template.Execute(wr, r.RenderArgs)
	if err == nil {
		return
	}

	var templateContent []string
	templateName, line, description := parseTemplateError(err)
	var content = ""
	if templateName == "" {
		templateName = r.Template.Name()
		content = r.PathContent[templateName]
	} else {
		content = r.PathContent[templateName]
	}
	if content != "" {
		templateContent = strings.Split(content, "\n")
	}

	compileError := &revel.Error{
		Title:       "Template Execution Error",
		Path:        templateName,
		Description: description,
		Line:        line,
		SourceLines: templateContent,
	}

	// 这里, 错误!!
	// 这里应该导向到本主题的错误页面
	resp.Status = 500
	ErrorResult{r.RenderArgs, compileError, r.IsPreview, r.CurBlogTpl}.Apply(req, resp)
}
开发者ID:nosqldb,项目名称:zhujian,代码行数:32,代码来源:Template.go


示例7: Apply

func (r *StreamConvertResult) Apply(req *revel.Request, resp *revel.Response) {
	resp.Out.Header().Add("Access-Control-Allow-Origin", "*")

	resp.WriteHeader(http.StatusOK, "audio/mp3")

	logger := func(line string) {
		if revel.DevMode {
			fmt.Println(line)
		}
	}

	tmpDir, err := ioutil.TempDir("", "youtube-to-koofr")
	if err != nil {
		revel.ERROR.Println(err)
		return
	}

	defer func() {
		os.RemoveAll(tmpDir)
	}()

	fileName, err := models.YoutubeDl(r.url, tmpDir, logger)
	if err != nil {
		revel.ERROR.Println(err)
		return
	}

	filePath := path.Join(tmpDir, fileName)

	f, err := os.Open(filePath)

	if err != nil {
		revel.ERROR.Println(err)
		return
	}

	_, err = io.Copy(resp.Out, f)

	if err != nil {
		revel.ERROR.Println(err)
		return
	}

	return
}
开发者ID:bancek,项目名称:youtube-to-koofr,代码行数:45,代码来源:stream.go


示例8: Apply

func (r *RenderTemplateResult) Apply(req *revel.Request, resp *revel.Response) {
	// Handle panics when rendering templates.
	defer func() {
		if err := recover(); err != nil {
		}
	}()

	chunked := revel.Config.BoolDefault("results.chunked", false)

	// If it's a HEAD request, throw away the bytes.
	out := io.Writer(resp.Out)
	if req.Method == "HEAD" {
		out = ioutil.Discard
	}

	// In a prod mode, write the status, render, and hope for the best.
	// (In a dev mode, always render to a temporary buffer first to avoid having
	// error pages distorted by HTML already written)
	if chunked && !revel.DevMode {
		resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")
		r.render(req, resp, out) // 这里!!!
		return
	}

	// Render the template into a temporary buffer, to see if there was an error
	// rendering the template.  If not, then copy it into the response buffer.
	// Otherwise, template render errors may result in unpredictable HTML (and
	// would carry a 200 status code)
	var b bytes.Buffer
	r.render(req, resp, &b)
	if !chunked {
		resp.Out.Header().Set("Content-Length", strconv.Itoa(b.Len()))
	}
	resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")
	b.WriteTo(out)
}
开发者ID:nosqldb,项目名称:zhujian,代码行数:36,代码来源:Template.go


示例9: Apply

// Apply writes the pdf file.
func (r ResumePDF) Apply(req *revel.Request, resp *revel.Response) {
	resp.Out.Header().Set("Content-Disposition", `inline; filename="rafael_chargels_resume.pdf"`)

	pdf := gofpdf.New("P", "pt", "letter", "./fonts/")

	header := func(text string) {
		pdf.Ln(4)
		pdf.SetFont("Arial", "B", 16)
		pdf.CellFormat(0, 30, strings.ToUpper(text), "", 1, "L", false, 0, "")
	}

	writeBullet := func(text string) {
		pdf.SetFont("Arial", "", 11)
		pdf.Ln(4)
		pdf.SetFillColor(0, 0, 0)
		pdf.CellFormat(20, 15, "", "", 0, "L", false, 0, "")

		x := pdf.GetX()
		y := pdf.GetY()
		pdf.Circle(x-5, y+7, 2, "F")
		pdf.MultiCell(0, 15, cleanStr(text), "", "L", false)
	}

	writeEducation := func(education domain.Education) {
		pdf.SetFont("Arial", "B", 11)
		pdf.Ln(4)
		pdf.CellFormat(0, 15, education.Institution+" - "+education.Year, "", 1, "L", false, 0, "")
		pdf.SetFont("Arial", "", 11)
		pdf.CellFormat(0, 15, education.Location, "", 1, "L", false, 0, "")
		pdf.CellFormat(0, 15, education.Degree, "", 1, "L", false, 0, "")
	}

	writeJob := func(job domain.Job) {
		pdf.SetFont("Arial", "B", 11)
		pdf.Ln(4)
		pdf.CellFormat(0, 15, job.Start+" - "+job.End, "", 1, "L", false, 0, "")
		pdf.CellFormat(0, 15, job.Title, "", 1, "L", false, 0, "")
		pdf.CellFormat(0, 15, job.Company, "", 1, "L", false, 0, "")
		pdf.SetFont("Arial", "BI", 11)
		pdf.CellFormat(0, 15, job.Location, "", 1, "L", false, 0, "")
		pdf.SetFont("Arial", "", 11)
		pdf.Ln(8)
		pdf.CellFormat(20, 15, "", "", 0, "L", false, 0, "")
		pdf.MultiCell(0, 15, cleanStr(job.Description), "", "L", false)
		pdf.Ln(8)
		pdf.SetFont("Arial", "I", 11)
		pdf.CellFormat(20, 15, "", "", 0, "L", false, 0, "")
		pdf.MultiCell(0, 15, cleanStr(job.Skills), "", "L", false)
		pdf.Ln(8)
	}

	pdf.SetTitle("Rafael Pacheco Chargel - Resume", true)
	pdf.SetAuthor("Rafael Pacheco Chargel", true)
	pdf.SetMargins(30, 30, 30)
	pdf.SetAutoPageBreak(true, 30)
	pdf.AddPage()
	pdf.SetFont("Helvetica", "B", 11)
	pdf.CellFormat(0, 15, "Rafael Pacheco Chargel", "", 1, "R", false, 0, "")
	pdf.SetFont("Helvetica", "", 11)
	pdf.CellFormat(0, 15, "http://zcarioca.net", "", 1, "R", false, 0, "")
	header("Summary")

	pdf.SetFont("Arial", "", 11)
	pdf.MultiCell(0, 15, cleanStr(r.resume.Summary), "", "L", false)

	header("Experience")
	for _, job := range r.resume.Experience.Jobs {
		writeJob(job)
	}

	header("Other Skills")
	writeBullet("Skills: " + r.resume.AdditionalSkills)
	writeBullet("Languages: " + r.resume.AdditionalLanguages)

	header("Education")
	writeEducation(r.resume.Education)

	resp.WriteHeader(http.StatusOK, "application/pdf")
	pdf.Output(resp.Out)
}
开发者ID:rchargel,项目名称:goblog,代码行数:81,代码来源:resume.go


示例10: Apply

func (r LoginResult) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(r.StatusCode, "text/html")
	resp.Out.Write([]byte(r.Message))
}
开发者ID:mweiss,项目名称:samples,代码行数:4,代码来源:app.go


示例11: Apply

func (r OctetResponse) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "application/octet-stream")
	resp.Out.Write(r)
}
开发者ID:Helstedxd,项目名称:LoL-Replay,代码行数:4,代码来源:app.go


示例12: Apply

func (r RenderHtmlResult) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "text/html")
	resp.Out.Write([]byte(r.html))
}
开发者ID:thnguyn2,项目名称:WebGPU,代码行数:4,代码来源:controllers.go


示例13: Apply

func (jr JpegResponse) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "image/jpeg")
	resp.Out.Write([]byte(jr))
}
开发者ID:toshi3221,项目名称:pazu,代码行数:4,代码来源:theta.go


示例14: Apply

func (r Ca) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "image/png")
}
开发者ID:nosqldb,项目名称:zhujian,代码行数:3,代码来源:CaptchaController.go



注:本文中的github.com/revel/revel.Response类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang revel.Validation类代码示例发布时间:2022-05-28
下一篇:
Golang revel.Params类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap