本文整理汇总了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
}
示例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
}
示例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)})
}
示例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,
},
})
}
}
示例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()))
}
}
示例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,
},
})
}
}
示例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),
},
})
}
}
示例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))
}
示例9: downloadHandler
func downloadHandler(render render.Render, params martini.Params) {
dat, _ := ioutil.ReadFile("./upload/" + params["id"])
render.Data(200, dat)
}