예제 #1
0
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
0
파일: server.go 프로젝트: hiproz/vodka
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
0
파일: server.go 프로젝트: hiproz/vodka
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)
}
예제 #4
0
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)
}
예제 #5
0
파일: app.go 프로젝트: xqbumu/zenpress
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)
}
예제 #6
0
파일: server.go 프로젝트: insionng/vodka
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+"!")
}
예제 #7
0
파일: server.go 프로젝트: insionng/vodka
func accessible(c vodka.Context) error {
	return c.String(http.StatusOK, "Accessible")
}
예제 #8
0
파일: server.go 프로젝트: hiproz/vodka
// Handler
func hello(c *vodka.Context) error {
	return c.String(http.StatusOK, "Hello, World!\n")
}
예제 #9
0
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")

}
예제 #10
0
func NoJwtHandler(self *vodka.Context) error {
	return self.String(http.StatusOK, "NoJwtHandler")
}
예제 #11
0
func HelloHandler(self vodka.Context) error {
	return self.String(http.StatusOK, "Hello, Vodka!")
}