本文整理汇总了Golang中github.com/insionng/vodka.Context.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Request方法的具体用法?Golang Context.Request怎么用?Golang Context.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/insionng/vodka.Context
的用法示例。
在下文中一共展示了Context.Request方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LikeHandler
func LikeHandler(self *vodka.Context) error {
if helper.IsSpider(self.Request().UserAgent()) != true {
name := self.FormEscape(":name")
id, _ := self.ParamInt64(":id")
if name == "topic" {
tp := models.GetTopic(id)
tp.Hotup = tp.Hotup + 1
tp.Hotscore = helper.Hotness_Score(tp.Hotup, tp.Hotdown)
tp.Hotness = helper.Hotness(tp.Hotup, tp.Hotdown, time.Now())
models.PutTopic(id, tp)
return self.String(http.StatusOK, "%v", tp.Hotup)
} else if name == "node" {
nd := models.GetNode(id)
nd.Hotup = nd.Hotup + 1
nd.Hotscore = helper.Hotness_Score(nd.Hotup, nd.Hotdown)
nd.Hotness = helper.Hotness(nd.Hotup, nd.Hotdown, time.Now())
models.PutNode(id, nd)
return self.Status(200)
}
}
return self.Status(401)
}
示例2: upload
func upload(c *vodka.Context) error {
req := c.Request()
// req.ParseMultipartForm(16 << 20) // Max memory 16 MiB
// Read form fields
name := c.Form("name")
email := c.Form("email")
// Read files
files := req.MultipartForm.File["files"]
for _, f := range files {
// Source file
src, err := f.Open()
if err != nil {
return err
}
defer src.Close()
// Destination file
dst, err := os.Create(f.Filename)
if err != nil {
return err
}
defer dst.Close()
if _, err = io.Copy(dst, src); err != nil {
return err
}
}
return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.",
name, email, len(files))
}
示例3: mustWrapHandleFunc
func (ceh *customVodkaHandler) mustWrapHandleFunc(c vodka.Context) vodka.HandlerFunc {
if _, ok := c.Request().(*standard.Request); ok {
return standard.WrapHandler(ceh.httpHandler)
} else if _, ok = c.Request().(*fasthttp.Request); ok {
return NewFastHTTPVodkaAdaptor(ceh.httpHandler)
}
log.Fatal("Unknown HTTP implementation")
return nil
}
示例4: NewReplyPostHandler
func NewReplyPostHandler(self *vodka.Context) error {
tid := self.FormInt64("comment_parent")
session := sessions.Default(self)
var user models.User
val := session.Get("user")
if val != nil {
user = val.(models.User)
}
sess_userid := user.Id
gmt, _ := self.Request().Cookie("gmt")
if gmt != nil {
if _, err := url.QueryUnescape(gmt.Value); err == nil {
author := self.FormEscape("author")
email := self.FormEscape("email")
website := self.FormEscape("website")
rc := self.FormEscape("comment")
if author != "" && email != "" && tid != 0 && rc != "" {
if err := models.AddReply(tid, sess_userid, rc, author, email, website); err != nil {
return err
}
return self.Redirect(302, fmt.Sprintf("/view/", tid))
} else {
return self.Redirect(302, "/")
}
} else {
return self.Redirect(302, "/")
}
} else {
return self.Redirect(302, "/")
}
}
示例5: request
func request(c vodka.Context) error {
req := c.Request().(*standard.Request).Request
format := "<pre><strong>Request Information</strong>\n\n<code>Protocol: %s\nHost: %s\nRemote Address: %s\nMethod: %s\nPath: %s\n</code></pre>"
return c.HTML(http.StatusOK, fmt.Sprintf(format, req.Proto, req.Host, req.RemoteAddr, req.Method, req.URL.Path))
}
示例6: MainHandler
func MainHandler(self *vodka.Context) error {
data := make(map[string]interface{})
///
data["nodes"] = models.GetAllNode()
data["nodes_hotness_topbar"] = models.GetAllNodeByCid(0, 0, 16, 0, "hotness")
data["topics_5s"] = models.GetAllTopic(0, 5, "id")
data["topics_10s"] = models.GetAllTopic(0, 10, "id")
data["nodes_10s"] = models.GetAllNodeByCid(0, 0, 10, 0, "id")
data["replys_5s"] = models.GetReplyByPid(0, 0, 5, "id")
data["replys_10s"] = models.GetReplyByPid(0, 0, 10, "id")
data["author"] = models.GetKV("author")
data["title"] = models.GetKV("title")
data["title_en"] = models.GetKV("title_en")
data["keywords"] = models.GetKV("keywords")
data["description"] = models.GetKV("description")
data["company"] = models.GetKV("company")
data["copyright"] = models.GetKV("copyright")
data["site_email"] = models.GetKV("site_email")
data["tweibo"] = models.GetKV("tweibo")
data["sweibo"] = models.GetKV("sweibo")
data["timenow"] = time.Now()
data["statistics"] = models.GetKV("statistics")
data["remoteproto"] = self.Request().Proto
data["remotehost"] = self.Request().Host
data["remoteos"] = runtime.GOOS
data["remotearch"] = runtime.GOARCH
data["remotecpus"] = runtime.NumCPU()
data["golangver"] = runtime.Version()
///
page, _ := self.ParamInt64("page")
curtab, _ := self.ParamInt64("tab")
cid, _ := self.ParamInt64(":cid")
limit := 25
home := "false"
if cid == 0 {
home = "true"
}
data["home"] = home
data["curcate"] = cid
data["curtab"] = curtab
topics_rcs := len(models.GetAllTopicByCid(cid, 0, 0, 0, "hotness"))
topics_pages, topics_pageout, topics_beginnum, topics_endnum, offset := helper.Pages(topics_rcs, int(page), limit)
data["topics_latest"] = models.GetAllTopicByCid(cid, offset, limit, 0, "id")
data["topics_hotness"] = models.GetAllTopicByCid(cid, offset, limit, 0, "hotness")
data["topics_views"] = models.GetAllTopicByCid(cid, offset, limit, 0, "views")
data["topics_reply_count"] = models.GetAllTopicByCid(cid, offset, limit, 0, "reply_count")
data["topics_pagesbar_tab1"] = helper.Pagesbar("tab=1&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
data["topics_pagesbar_tab2"] = helper.Pagesbar("tab=2&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
data["topics_pagesbar_tab3"] = helper.Pagesbar("tab=3&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
data["topics_pagesbar_tab4"] = helper.Pagesbar("tab=4&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
nodes_rcs := len(models.GetAllNodeByCid(cid, 0, 0, 0, "hotness"))
nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, offset := helper.Pages(nodes_rcs, int(page), limit)
data["nodes_latest"] = models.GetAllNodeByCid(cid, offset, limit, 0, "id")
data["nodes_hotness"] = models.GetAllNodeByCid(cid, offset, limit, 0, "hotness")
data["nodes_pagesbar_tab5"] = helper.Pagesbar("tab=5&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1)
data["nodes_pagesbar_tab6"] = helper.Pagesbar("tab=6&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1)
return self.Render(http.StatusOK, "index.html", nil)
}