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


Golang Render.Data方法代碼示例

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


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

示例1: Answer

func Answer(req *http.Request, r render.Render) {
	returnData := make(map[string]interface{})
	if req.Method == "GET" {
		blankList, choiceList, judgeList := appService.GetTitleId(1, 1, 1)
		returnData["blankList"] = blankList
		returnData["choiceList"] = choiceList
		returnData["judgeList"] = judgeList
		r.HTML(200, "answer", returnData)
		return
	}
	req.ParseForm()
	values := req.Form
	records := values.Get("records")
	if records == "" {
		r.Data(500, []byte("error"))
	}
	name, recordsList, err := appService.CheckRecords(records)
	if err != nil {
		r.Data(500, []byte("appService.CheckRecords error"))
	}
	returnData["name"] = name
	returnData["list"] = recordsList
	r.HTML(200, "record", returnData)
	return
}
開發者ID:leisunstar,項目名稱:hxs,代碼行數:25,代碼來源:api.go

示例2: Index

func Index(session sessions.Session, r render.Render) {
	id, ok := session.Get("user_id").(int64)
	if !ok {
		r.Data(200, []byte("error"))
		return
	}

	list, err := ga.GetPermissionByUserId(id)
	if err != nil {
		r.Data(200, []byte("get error"))
		return
	}

	r.HTML(200, "list", map[string]interface{}{"list": list})
	return
}
開發者ID:go-galaxy,項目名稱:galaxy,代碼行數:16,代碼來源:example.go

示例3: Markdown

// Markdown renders a POST request into HTML.
func (ap ApiRender) Markdown(r render.Render, req *http.Request) {
	if err := req.ParseForm(); err != nil {
		r.Data(500, []byte(err.Error()))
		return
	}

	if _, ok := req.Form["raw"]; !ok {
		r.Data(500, []byte("No Data"))
		return
	}

	raw := req.Form["raw"][0]
	data := util.Markdown([]byte(raw))

	r.JSON(200, apiRenderResponse{Data: string(data)})
}
開發者ID:supermouseno1,項目名稱:b,代碼行數:17,代碼來源:api.go

示例4: getCertificates

func getCertificates(req *http.Request, params martini.Params, r render.Render) {

	format := req.URL.Query().Get("format")

	newCA, err := ca.NewCA(config["root-dir"])
	if err != nil {
		panic(err)
	}

	id := params["id"]
	idInt, err := strconv.Atoi(id)
	if err != nil {
		r.JSON(401, map[string]interface{}{
			"result": "wrong id",
		})
		return
	}
	cert, err := newCA.GetCertificate(int64(idInt))
	if err != nil {
		r.JSON(401, map[string]interface{}{
			"result": "cannot get cert",
		})
		return
	}

	pem, err := cert.ToPEM()
	if err != nil {
		r.JSON(401, map[string]interface{}{
			"result": "cannot get cert",
		})
		return
	}

	if format == "file" {
		r.Data(200, pem)
	} else {
		r.JSON(200, map[string]interface{}{
			"certificate": map[string]interface{}{
				"id":  cert.GetSerialNumber().Int64(),
				"crt": string(pem),
				//"csr": csr,
			},
		})
	}

}
開發者ID:brimstone,項目名稱:sbuca,代碼行數:46,代碼來源:certificates.go

示例5: Create

// Create allows for the creation of new posts. It returns a 204
// response on creation or a 500 response on error.
func (ap ApiPosts) Create(r render.Render, req *http.Request) {
	var (
		post models.Post
		err  error
		t    = "urlencoded"
		p    interface{}
	)
	root := util.Config().App.PostsDir
	contentType := req.Header.Get("content-type")

	if strings.Contains(contentType, "application/json") {
		t = "json"
	}

	switch t {
	case "json":
		dec := json.NewDecoder(req.Body)
		err = dec.Decode(&post)
		p = post
	default:
		err = req.ParseForm()
		p = req.Form
	}

	if err != nil {
		r.Data(500, []byte(err.Error()))
		return
	}

	if err = models.SavePost(root, p); err == nil {
		r.Data(204, []byte("Created"))
	} else {
		r.Data(500, []byte(err.Error()))
	}
}
開發者ID:supermouseno1,項目名稱:b,代碼行數:37,代碼來源:api.go

示例6: postCertificates

func postCertificates(req *http.Request, params martini.Params, r render.Render) {

	csrString := req.PostFormValue("csr")
	format := req.URL.Query().Get("format")

	csr, err := pkix.NewCertificateRequestFromPEM([]byte(csrString))
	if err != nil {
		panic(err)
	}

	newCA, err := ca.NewCA(config["root-dir"])
	if err != nil {
		panic(err)
	}

	cert, err := newCA.IssueCertificate(csr)
	if err != nil {
		panic(err)
	}

	certPem, err := cert.ToPEM()
	if err != nil {
		panic(err)
	}
	if format == "file" {
		r.Data(200, certPem)
	} else {
		r.JSON(200, map[string]interface{}{
			"certificate": map[string]interface{}{
				"id":  cert.GetSerialNumber().Int64(),
				"crt": string(certPem),
				//"csr": csr,
			},
		})
	}
}
開發者ID:brimstone,項目名稱:sbuca,代碼行數:36,代碼來源:certificates.go

示例7: getCA

func getCA(req *http.Request, params martini.Params, r render.Render) {

	format := req.URL.Query().Get("format")

	newCA, err := ca.NewCA(config["root-dir"])
	if err != nil {
		panic(err)
	}

	pem, err := newCA.Certificate.ToPEM()
	if err != nil {
		panic(err)
	}

	if format == "file" {
		r.Data(200, pem)
	} else {
		r.JSON(200, map[string]interface{}{
			"ca": map[string]interface{}{
				"crt": string(pem),
			},
		})
	}
}
開發者ID:brimstone,項目名稱:sbuca,代碼行數:24,代碼來源:ca.go

示例8: routeGetAdAsset

func routeGetAdAsset(r render.Render, res http.ResponseWriter, req *http.Request, params martini.Params) {
	slot := params["slot"]
	id := params["id"]
	ad := getAd(req, slot, id)
	if ad == nil {
		r.JSON(404, map[string]string{"error": "not_found"})
		return
	}
	content_type := "application/octet-stream"
	if ad.Type != "" {
		content_type = ad.Type
	}

	res.Header().Set("Content-Type", content_type)
	data, _ := rd.Get(assetKey(slot, id)).Result()

	range_str := req.Header.Get("Range")
	if range_str == "" {
		r.Data(200, []byte(data))
		return
	}

	re := regexp.MustCompile("^bytes=(\\d*)-(\\d*)$")
	m := re.FindAllStringSubmatch(range_str, -1)

	if m == nil {
		r.Status(416)
		return
	}

	head_str := m[0][1]
	tail_str := m[0][2]

	if head_str == "" && tail_str == "" {
		r.Status(416)
		return
	}

	head := 0
	tail := 0

	if head_str != "" {
		head, _ = strconv.Atoi(head_str)
	}
	if tail_str != "" {
		tail, _ = strconv.Atoi(tail_str)
	} else {
		tail = len(data) - 1
	}

	if head < 0 || head >= len(data) || tail < 0 {
		r.Status(416)
		return
	}

	range_data := data[head:(tail + 1)]
	content_range := fmt.Sprintf("bytes %d-%d/%d", head, tail, len(data))
	res.Header().Set("Content-Range", content_range)
	res.Header().Set("Content-Length", strconv.Itoa(len(range_data)))

	r.Data(206, []byte(range_data))
}
開發者ID:n0bisuke,項目名稱:isucon4,代碼行數:62,代碼來源:app.go

示例9: downloadHandler

func downloadHandler(render render.Render, params martini.Params) {
	dat, _ := ioutil.ReadFile("./upload/" + params["id"])
	render.Data(200, dat)
}
開發者ID:aaltaev,項目名稱:tables,代碼行數:4,代碼來源:app.go


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