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


Golang Response.WriteHeader方法代碼示例

本文整理匯總了Golang中github.com/revel/revel.Response.WriteHeader方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response.WriteHeader方法的具體用法?Golang Response.WriteHeader怎麽用?Golang Response.WriteHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/revel/revel.Response的用法示例。


在下文中一共展示了Response.WriteHeader方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: Apply

func (r Ca) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "image/png")
}
開發者ID:nosqldb,項目名稱:zhujian,代碼行數:3,代碼來源:CaptchaController.go

示例11: 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

示例12: 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

示例13: 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


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