本文整理汇总了Golang中github.com/insionng/vodka.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/insionng/vodka.Context
的用法示例。
在下文中一共展示了Context.String方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TokenHandler
func TokenHandler(self *vodka.Context) error {
var claims = map[string]interface{}{}
claims["token"] = "insion's-Token"
token, err := NewToken(JWTContextKey, claims)
if err != nil {
return err
}
// show the token use for test
return self.String(http.StatusOK, "%s", token)
}
示例4: TokenHandler
func TokenHandler(self *vodka.Context) error {
var claims = map[string]interface{}{}
claims["username"] = "Insion"
token, err := jwt.NewToken(key, claims)
if err != nil {
return err
}
// show the token use for test
return self.String(http.StatusOK, "%s", token)
}
示例5: restricted
func restricted(c vodka.Context) error {
user := c.Get("user").(*jwt.Token)
claims := user.Claims.(jwt.MapClaims)
name := claims["name"].(string)
return c.String(http.StatusOK, "Welcome "+name+"!")
}
示例6: accessible
func accessible(c vodka.Context) error {
return c.String(http.StatusOK, "Accessible")
}
示例7: hello
// Handler
func hello(c *vodka.Context) error {
return c.String(http.StatusOK, "Hello, World!\n")
}
示例8: JwtHandler
func JwtHandler(self *vodka.Context) error {
Claims := Claims(self)
fmt.Printf("Got token %v by JwtHandler. ", Claims["token"] == "insion's-Token")
return self.String(http.StatusOK, "JwtHandler")
}
示例9: NoJwtHandler
func NoJwtHandler(self *vodka.Context) error {
return self.String(http.StatusOK, "NoJwtHandler")
}
示例10: HelloHandler
func HelloHandler(self vodka.Context) error {
return self.String(http.StatusOK, "Hello, Vodka!")
}