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


Golang revel.Response類代碼示例

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


在下文中一共展示了Response類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Apply

func (r RrdFetchTsvResult) Apply(req *revel.Request, resp *revel.Response) {
	revel.TRACE.Printf("Apply start\n")
	resp.WriteHeader(http.StatusOK, "text/tab-separated-values")

	resp.Out.Write([]byte("date\tvalue\n"))
	data := r.data
	row := 0
	for ti := data.Start.Add(data.Step); ti.Before(data.End) || ti.Equal(data.End); ti = ti.Add(data.Step) {
		v := data.ValueAt(0, row)
		line := fmt.Sprintf("%d\t%e\n", ti.Unix(), v)
		resp.Out.Write([]byte(line))
		row++
	}
	revel.TRACE.Printf("Apply exit\n")
	/*
		origStep := r.origStep * 1000
		jStep := origStep / int(step)
		if jStep < 1 {
			jStep = 1
		}

		// TODO: Calculate max, average and such if jStep > 1
		revel.TRACE.Printf("jStep=%d, step=%d, origStep=%d\n", jStep, step, origStep)
		for j := 0; j < data.RowLen; j += jStep {
			t := start + int64(j + 1) * step
			v := data.ValueAt(0, j)
			if j > 0 && math.IsNaN(v) {
				break
			}
			line := fmt.Sprintf("%d\t%e\n", t, v)
			resp.Out.Write([]byte(line))
		}
	*/
}
開發者ID:hnakamur,項目名稱:goemon,代碼行數:34,代碼來源:api.go

示例2: Apply

// Custom responses -----------------------------------------------------------
// Custom response for image
func (r ImageResponse) Apply(req *revel.Request, resp *revel.Response) {

	// FIX:
	// If settings loaded out of actions then revel throws nil pointer, so we
	// load here the first time only
	if font == nil {
		fontPath, _ := revel.Config.String("gummyimage.fontpath")
		font, _ = gummyimage.LoadFont(fontPath)
	}

	resp.WriteHeader(http.StatusOK, "image/png")

	g, _ := gummyimage.NewDefaultGummy(r.sizeX, r.sizeY, r.bgColor)
	g.Font = font

	// Custom text?
	if len(r.text) == 0 {
		g.DrawTextSize(r.fgColor)
	} else {
		g.DrawTextCenter(r.text, r.fgColor)
	}

	b := new(bytes.Buffer)
	g.Get(r.format, b)
	resp.Out.Write(b.Bytes())
}
開發者ID:slok,項目名稱:gummyimage,代碼行數:28,代碼來源:app.go

示例3: Apply

func (r dynamicImage) Apply(req *revel.Request, resp *revel.Response) {
	buffer := bytes.NewBufferString("digraph callgraph{\n")
	if r.searchType == "caller" {
		var visitedCallers = sort.StringSlice{r.funcName}
		callers, ok := allCallers[r.dataSource]
		if ok {
			r.calcCalls(&callers, r.funcName, 0, buffer, visitedCallers)
		}
	} else {
		var visitedCallees = sort.StringSlice{r.funcName}
		callees, ok := allCallees[r.dataSource]
		if ok {
			r.calcCalls(&callees, r.funcName, 0, buffer, visitedCallees)
		}
	}
	buffer.WriteString("}")

	/* set direction */
	param0 := "-Grankdir=" + r.direction
	cmdDot := exec.Command("dot", param0, "-Tpng")
	cmdDot.Stdin = bytes.NewReader(buffer.Bytes())

	output, err := cmdDot.Output()
	if err != nil {
		resp.WriteHeader(http.StatusOK, "text/html")
		resp.Out.Write([]byte("No image: " + err.Error()))
		return
	}

	resp.WriteHeader(http.StatusOK, "image/png")
	resp.Out.Write(output)
}
開發者ID:jinlf,項目名稱:callgraph,代碼行數:32,代碼來源:app.go

示例4: Apply

// Render the Templates into the Response, handles errors and panics using the
// same mechanisms of revel.
func (r *RenderLayoutTemplateResult) Apply(req *revel.Request, resp *revel.Response) {
	// Handle panics when rendering templates.
	defer func() {
		if err := recover(); err != nil {
			revel.ERROR.Println(err)
			revel.PlaintextErrorResult{fmt.Errorf("Template Execution Panic in %s:\n%s",
				r.Template.Name(), err)}.Apply(req, resp)
		}
	}()

	chunked := revel.Config.BoolDefault("results.chunked", false)
	r.RenderTmpl[""] = r.Template
	r.RenderArgs["ContentForItems"] = r.RenderTmpl

	// 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")
		if r.Layout == nil {
			r.render(req, resp, out)
		} else {
			r.renderWithLayout(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
	if r.Layout == nil {
		r.render(req, resp, &b)
	} else {
		r.renderWithLayout(req, resp, &b)
	}

	if !chunked {
		resp.Out.Header().Set("Content-Length", strconv.Itoa(b.Len()))
	}
	resp.WriteHeader(http.StatusOK, "text/html")
	b.WriteTo(out)
}
開發者ID:hura,項目名稱:yield,代碼行數:52,代碼來源:results.go

示例5: Apply

func (r FResponse404) Apply(req *revel.Request, resp *revel.Response) {
	var b []byte
	var err error
	if revel.Config.BoolDefault("results.pretty", false) {
		b, err = json.MarshalIndent(r.obj, "", "  ")
	} else {
		b, err = json.Marshal(r.obj)
	}

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

	resp.WriteHeader(http.StatusNotFound, "application/json")
	resp.Out.Write(b)
}
開發者ID:Chandler,項目名稱:goflesh,代碼行數:17,代碼來源:api.go

示例6: renderError

func (r *RenderLayoutTemplateResult) renderError(req *revel.Request, resp *revel.Response, err error) {
	var templateContent []string
	templateName, line, description := parseTemplateError(err)
	if templateName == "" {
		templateName = r.Layout.Name()
		templateContent = r.Layout.Content()
	} else {
		if tmpl, err := revel.MainTemplateLoader.Template(templateName); err == nil {
			templateContent = tmpl.Content()
		}
	}
	compileError := &revel.Error{
		Title:       "Layout Execution Error",
		Path:        templateName,
		Description: description,
		Line:        line,
		SourceLines: templateContent,
	}
	resp.Status = 500
	revel.ERROR.Printf("Template Execution Error (in %s): %s", templateName, description)
	revel.ErrorResult{r.RenderArgs, compileError}.Apply(req, resp)
}
開發者ID:hura,項目名稱:yield,代碼行數:22,代碼來源:results.go

示例7: Apply

func (r RssXml) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "application/xml")
	resp.Out.Write([]byte(r))
}
開發者ID:netsharec,項目名稱:ironzebra,代碼行數:4,代碼來源:blog.go

示例8: Apply

// This will get called for Cert/Key downloads to manage HTTP Headers
func (r Download) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "text/plain") //Browser can open
	//resp.WriteHeader(http.StatusOK, "application/text")//Forces Browser to download
	resp.Out.Write([]byte(r))
}
開發者ID:shaheemirza,項目名稱:CAGo,代碼行數:6,代碼來源:project.go

示例9: Apply

func (r LoginResult) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(r.StatusCode, "text/html")
	resp.Out.Write([]byte(r.Message))
}
開發者ID:huaguzi,項目名稱:revel,代碼行數:4,代碼來源:app.go

示例10: Apply

func (r HTML) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(http.StatusOK, "text/html")
	resp.Out.Write([]byte(r))
}
開發者ID:pavelb,項目名稱:gorss,代碼行數:4,代碼來源:reddit.go

示例11: Apply

// Set HTTP header types for returning image(not html page)
func (r JPGImage) Apply(req *revel.Request, resp *revel.Response) {
	// Output screenshot
	resp.WriteHeader(http.StatusOK, "image/jpg")
	resp.Out.Write(r)
}
開發者ID:JustinJudd,項目名稱:go_snappshot,代碼行數:6,代碼來源:snappshot.go

示例12: Apply

func (u Utf8Result) Apply(req *revel.Request, resp *revel.Response) {
	resp.WriteHeader(resp.Status, "text/plain; charset=utf-8")
	resp.Out.Write([]byte(u))
}
開發者ID:pombredanne,項目名稱:goqdb,代碼行數:4,代碼來源:helpers.go

示例13: Apply

// Marshals the Responder instance as the body response as Json.
// The Responder's implementation of GetHttpStatus() will be used
// as the Http status code in the response.
// The Responder's implementation of GetErroLogString() will be used
// to log to revel.Error.
func (r JsonErrorResult) Apply(req *revel.Request, resp *revel.Response) {
	responseData, _ := json.Marshal(r.Responder)
	resp.WriteHeader((*r.Responder).GetHttpStatus(), "application/json")
	resp.Out.Write(responseData)
	revel.ERROR.Printf("Error response: HTTP-%d : %s", (*r.Responder).GetHttpStatus(), (*r.Responder).GetErroLogString())
}
開發者ID:shmifaats,項目名稱:rvljson,代碼行數:11,代碼來源:jsonerrors.go


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