• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang vodka.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/insionng/vodka.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: login

func login(c vodka.Context) error {
	username := c.FormValue("username")
	password := c.FormValue("password")

	if username == "jon" && password == "shhh!" {
		// Create token
		token := jwt.New(jwt.SigningMethodHS256)

		// Set claims
		claims := token.Claims.(jwt.MapClaims)
		claims["name"] = "Jon Snow"
		claims["admin"] = true
		claims["exp"] = time.Now().Add(time.Hour * 72).Unix()

		// Generate encoded token and send it as response.
		t, err := token.SignedString([]byte("secret"))
		if err != nil {
			return err
		}
		return c.JSON(http.StatusOK, map[string]string{
			"token": t,
		})
	}

	return vodka.ErrUnauthorized
}
开发者ID:insionng,项目名称:vodka,代码行数:26,代码来源:server.go


示例2: Render

// Render 渲染
func (r *Renderer) Render(w io.Writer, name string, ctx vodka.Context) error {
	template, err := r.getTemplate(name)
	if err != nil {
		return err
	}
	err = template.ExecuteWriter(ctx.GetStore(), w)
	return err
}
开发者ID:vodka-contrib,项目名称:pongor,代码行数:9,代码来源:pongor.go


示例3: createUser

func createUser(c vodka.Context) error {
	u := new(user)
	if err := c.Bind(u); err != nil {
		return err
	}
	users[u.ID] = *u
	return c.JSON(http.StatusCreated, u)
}
开发者ID:insionng,项目名称:vodka,代码行数:8,代码来源:users.go


示例4: NodeEditGetHandler

func NodeEditGetHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	nid, _ := self.ParamInt64(":nid")
	nid_handler := models.GetNode(nid)
	data["inode"] = nid_handler
	data["icategory"] = models.GetCategory(nid_handler.Pid)

	return self.Render(http.StatusOK, "node_edit.html", data)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:9,代码来源:EditNode.go


示例5: TopicEditGetHandler

func TopicEditGetHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	tid, _ := self.ParamInt64(":tid")
	tid_handler := models.GetTopic(tid)
	data["topic"] = tid_handler
	data["inode"] = models.GetNode(tid_handler.Nid)

	return self.Render(http.StatusOK, "topic_edit.html", data)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:9,代码来源:EditTopic.go


示例6: upload

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)
}
开发者ID:hiproz,项目名称:vodka,代码行数:56,代码来源:server.go


示例7: 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
}
开发者ID:vodka-contrib,项目名称:vodkapprof,代码行数:10,代码来源:custom_vodka_handler.go


示例8: 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)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:11,代码来源:app.go


示例9: createUser

func createUser(c vodka.Context) error {
	u := &user{
		ID: seq,
	}
	if err := c.Bind(u); err != nil {
		return err
	}
	users[u.ID] = u
	seq++
	return c.JSON(http.StatusCreated, u)
}
开发者ID:insionng,项目名称:vodka,代码行数:11,代码来源:server.go


示例10: 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)
}
开发者ID:vodka-contrib,项目名称:jwt,代码行数:11,代码来源:jwt_test.go


示例11: SigninGetHandler

func SigninGetHandler(self *vodka.Context) error {

	session := sessions.Default(self)

	val := session.Get("user")
	if val != nil {
		return self.Redirect(302, "/")
	} else {
		return self.Render(http.StatusOK, "signin.html", nil)
	}

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:12,代码来源:SigninHandler.go


示例12: upload

func upload(c vodka.Context) error {
	// Read form fields
	name := c.FormValue("name")
	email := c.FormValue("email")

	//-----------
	// Read file
	//-----------

	// Source
	file, err := c.FormFile("file")
	if err != nil {
		return err
	}
	src, err := file.Open()
	if err != nil {
		return err
	}
	defer src.Close()

	// Destination
	dst, err := os.Create(file.Filename)
	if err != nil {
		return err
	}
	defer dst.Close()

	// Copy
	if _, err = io.Copy(dst, src); err != nil {
		return err
	}

	return c.HTML(http.StatusOK, fmt.Sprintf("<p>File %s uploaded successfully with fields name=%s and email=%s.</p>", file.Filename, name, email))
}
开发者ID:insionng,项目名称:vodka,代码行数:34,代码来源:server.go


示例13: ModifyCatPostHandler

func ModifyCatPostHandler(self *vodka.Context) error {

	cid, _ := self.ParamInt64("categoryid")

	cat_title := self.ParamEscape("title")
	cat_content := self.ParamEscape("content")
	if cid != 0 && cat_title != "" && cat_content != "" {
		var cat models.Category
		cat.Id = int64(cid)
		cat.Title = cat_title
		cat.Content = cat_content
		cat.Created = time.Now()
		models.UpdateCategory(cat.Id, cat)
		return self.Redirect(302, fmt.Sprintf("/category/%v/", cid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:18,代码来源:ModifyCategory.go


示例14: stream

func stream(c vodka.Context) error {
	res := c.Response().(*standard.Response).ResponseWriter
	gone := res.(http.CloseNotifier).CloseNotify()
	res.Header().Set(vodka.HeaderContentType, vodka.MIMETextHTMLCharsetUTF8)
	res.WriteHeader(http.StatusOK)
	ticker := time.NewTicker(1 * time.Second)
	defer ticker.Stop()

	fmt.Fprint(res, "<pre><strong>Clock Stream</strong>\n\n<code>")
	for {
		fmt.Fprintf(res, "%v\n", time.Now())
		res.(http.Flusher).Flush()
		select {
		case <-ticker.C:
		case <-gone:
			break
		}
	}
}
开发者ID:insionng,项目名称:vodka,代码行数:19,代码来源:server.go


示例15: NewTopicPostHandler

func NewTopicPostHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64("nodeid")
	cid := models.GetNode(nid).Pid
	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id
	author := user.Nickname

	tid_title := self.FormEscape("title")
	tid_content := self.FormEscape("content")

	if tid_title != "" && tid_content != "" {
		models.AddTopic(tid_title, tid_content, cid, nid, uid, author)
		return self.Redirect(302, fmt.Sprintf("/node/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:22,代码来源:NewTopic.go


示例16: updateUser

func updateUser(c vodka.Context) error {
	u := new(user)
	if err := c.Bind(u); err != nil {
		return err
	}
	id, _ := strconv.Atoi(c.Param("id"))
	users[id].Name = u.Name
	return c.JSON(http.StatusOK, users[id])
}
开发者ID:insionng,项目名称:vodka,代码行数:9,代码来源:server.go


示例17: NewCategoryPostHandler

func NewCategoryPostHandler(self *vodka.Context) error {

	t := self.FormEscape("title")
	c := self.FormEscape("content")
	if t != "" && c != "" {
		models.AddCategory(t, c)
	}
	return self.Redirect(302, "/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:9,代码来源:NewCategory.go


示例18: SignupPostHandler

func SignupPostHandler(self *vodka.Context) error {

	data := make(map[string]interface{})

	username := self.FormEscape("username")
	password := self.FormEscape("password")
	usererr := helper.CheckUsername(username)

	if usererr == false {
		e := errors.New("Username error, Please to again")
		data["UsernameErr"] = e.Error()
		return e
	}

	passerr := helper.CheckPassword(password)
	if passerr == false {
		e := errors.New("Password error, Please to again")
		data["PasswordErr"] = e.Error()
		return e
	}

	pwd := helper.EncryptHash(password, nil)

	//now := torgo.Date(time.Now(), "Y-m-d H:i:s")

	userInfo := models.CheckUserByNickname(username)

	fmt.Println(userInfo.Nickname)

	//  检查该用户是否已经被注册
	if userInfo.Nickname == "" {

		//注册用户
		regErr := models.AddUser(username+"@insion.co", username, "", pwd, 1)
		fmt.Println("reg:s")
		fmt.Println(regErr)
		fmt.Println("reg:e ")
		//注册成功设置session
		//	self.SetSession("userid", userInfo.Id)
		//	self.SetSession("username", userInfo.Nickname)
		//	self.SetSession("userrole", userInfo.Role)
		//	self.SetSession("useremail", userInfo.Email)
		return self.Redirect(302, "/signin/")

	} else {
		e := errors.New("User already exists")
		data["UsernameErr"] = e.Error()
		return e
	}
	return self.Render(http.StatusOK, "signup.html", data)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:51,代码来源:SignupHandler.go


示例19: NodeHandler

func NodeHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	page, _ := self.ParamInt64("page")
	nid, _ := self.ParamInt64(":nid")

	nid_handler := models.GetNode(nid)
	nid_handler.Views = nid_handler.Views + 1
	models.UpdateNode(nid, nid_handler)

	limit := 25
	rcs := len(models.GetAllTopicByNid(nid, 0, 0, 0, "hotness"))
	pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)
	data["pagesbar"] = helper.Pagesbar("", rcs, pages, pageout, beginnum, endnum, 1)
	data["nodeid"] = nid
	data["topics_hotness"] = models.GetAllTopicByNid(nid, offset, limit, 0, "hotness")
	data["topics_latest"] = models.GetAllTopicByNid(nid, offset, limit, 0, "id")

	if nid != 0 {
		return self.Render(http.StatusOK, "node.html", data)
	} else {
		return self.Redirect(302, "/")
	}

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:24,代码来源:NodeHandler.go


示例20: SearchHandler

func SearchHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	if keyword := self.FormEscape("keyword"); keyword != "" {
		page, _ := self.ParamInt("page")
		limit := 25

		rcs := len(*models.SearchTopic(keyword, 0, 0, "id"))
		pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)
		data["search_hotness"] = models.SearchTopic(keyword, offset, limit, "hotness")

		keywordz := "keyword=" + keyword + "&"
		data["pagesbar"] = helper.Pagesbar(keywordz, rcs, pages, pageout, beginnum, endnum, 1)

	}

	return self.Render(http.StatusOK, "search.html", data)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:17,代码来源:SearchHandler.go



注:本文中的github.com/insionng/vodka.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-23
下一篇:
Golang vodka.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap