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) }
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)) }
func upload(c *vodka.Context) error { mr, err := c.Request().MultipartReader() if err != nil { return err } // Read form field `name` part, err := mr.NextPart() if err != nil { return err } defer part.Close() b, err := ioutil.ReadAll(part) if err != nil { return err } name := string(b) // Read form field `email` part, err = mr.NextPart() if err != nil { return err } defer part.Close() b, err = ioutil.ReadAll(part) if err != nil { return err } email := string(b) // Read files i := 0 for { part, err := mr.NextPart() if err != nil { if err == io.EOF { break } return err } defer part.Close() file, err := os.Create(part.FileName()) if err != nil { return err } defer file.Close() if _, err := io.Copy(file, part); err != nil { return err } i++ } return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.", name, email, i) }
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) }
func TokenHandler(self *vodka.Context) error { var claims = map[string]interface{}{} claims["username"] = "******" token, err := jwt.NewToken(key, claims) if err != nil { return err } // show the token use for test return self.String(http.StatusOK, "%s", token) }
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+"!") }
func accessible(c vodka.Context) error { return c.String(http.StatusOK, "Accessible") }
// Handler func hello(c *vodka.Context) error { return c.String(http.StatusOK, "Hello, World!\n") }
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") }
func NoJwtHandler(self *vodka.Context) error { return self.String(http.StatusOK, "NoJwtHandler") }
func HelloHandler(self vodka.Context) error { return self.String(http.StatusOK, "Hello, Vodka!") }