本文整理匯總了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()
}
}
示例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
}
示例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)
}
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例10: Apply
func (r LoginResult) Apply(req *revel.Request, resp *revel.Response) {
resp.WriteHeader(r.StatusCode, "text/html")
resp.Out.Write([]byte(r.Message))
}
示例11: Apply
func (r OctetResponse) Apply(req *revel.Request, resp *revel.Response) {
resp.WriteHeader(http.StatusOK, "application/octet-stream")
resp.Out.Write(r)
}
示例12: Apply
func (r RenderHtmlResult) Apply(req *revel.Request, resp *revel.Response) {
resp.WriteHeader(http.StatusOK, "text/html")
resp.Out.Write([]byte(r.html))
}
示例13: Apply
func (jr JpegResponse) Apply(req *revel.Request, resp *revel.Response) {
resp.WriteHeader(http.StatusOK, "image/jpeg")
resp.Out.Write([]byte(jr))
}
示例14: Apply
func (r Ca) Apply(req *revel.Request, resp *revel.Response) {
resp.WriteHeader(http.StatusOK, "image/png")
}