本文整理汇总了Golang中github.com/chinakyc/AgBlog/app.ResponseWriter类的典型用法代码示例。如果您正苦于以下问题:Golang ResponseWriter类的具体用法?Golang ResponseWriter怎么用?Golang ResponseWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResponseWriter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DeleteArticle
func DeleteArticle(w app.ResponseWriter, r *app.Request) {
article_id, err := strconv.Atoi(r.PathParams["article_id"])
if err == nil {
article := models.Article{}
article.Find(article_id)
if article.ID != 0 {
article.Delete()
return
}
}
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
w.WriteHeader(404)
w.WriteJson(map[string]string{"error": "article no found"})
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:17,代码来源:article_controller.go
示例2: ServeHTTP
func (c articlesController) ServeHTTP(w app.ResponseWriter, r *app.Request) {
var err error
// default args
offset := 0
limit := c.PagePerNumberMAX
category_id := 0
err = nil
str_category_id := r.PathParams["category_id"]
if str_category_id != "" {
category_id, err = strconv.Atoi(str_category_id)
if err != nil {
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
category_id = 0
}
}
uri_params := r.URL.Query()
if limit_str := uri_params["limit"]; limit_str != nil {
limit, err = strconv.Atoi(limit_str[0])
if err != nil {
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
limit = c.PagePerNumberMAX
}
}
if offset_str := uri_params["offset"]; offset_str != nil {
offset, err = strconv.Atoi(offset_str[0])
if err != nil {
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
offset = 0
}
}
category := models.Category{ID: category_id}
articles := category.AllArticles(offset, limit)
w.WriteJson(articles)
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:41,代码来源:category_controller.go
示例3: PostArticle
func PostArticle(w app.ResponseWriter, r *app.Request) {
user := r.Env["user"].(*models.User)
title, markdown, category, html := generateArticleContent(r)
if title == "" {
w.WriteHeader(400)
w.WriteJson(map[string]string{"error": "missing stuff"})
return
}
// create article
article := models.Article{Title: title, Content: string(html), Markdown: markdown}
user.AddArticle(&article)
category.AddArticle(&article)
article.Create()
w.WriteJson(article)
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:19,代码来源:article_controller.go
示例4: ModifyArticle
func ModifyArticle(w app.ResponseWriter, r *app.Request) {
article_id, err := strconv.Atoi(r.PathParams["article_id"])
if err == nil {
title, markdown, _, html := generateArticleContent(r)
article := models.Article{}
article.Find(article_id)
if article.ID != 0 {
article.Title = title
article.Markdown = markdown
article.Content = string(html)
// category.AddArticle(&article)
article.Save()
w.WriteJson(article)
return
}
}
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
w.WriteHeader(404)
w.WriteJson(map[string]string{"error": "article no found"})
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:23,代码来源:article_controller.go
示例5: LoginController
func (self *authMiddware) LoginController(w app.ResponseWriter, r *app.Request) {
var tokenString string
data := jsonLoginDate{}
// Decode Json from request
err := r.DecodeJsonPayload(&data)
if err != nil {
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
w.WriteHeader(500)
w.WriteJson(map[string]string{"error": fmt.Sprintf("Error: %s", err)})
return
}
// extract
email := data.Email
password := data.Password
// use email get user
user := models.User{}
user.Find(email)
// validate password generate jwt tokenString
// user jwt we can ignore CRSF
if user.Validate(password) {
user.Last_seen = time.Now().UTC()
user.Save()
token := jwt.New(jwt.SigningMethodHS256)
token.Claims["email"] = user.Email
token.Claims["role"] = user.Role
token.Claims["exp"] = time.Now().Add(time.Hour * 6).UTC().Unix()
tokenString, err = token.SignedString(self.signingKey)
if err != nil {
logging.Logger.Error(fmt.Sprintf("Error: %s", err))
w.WriteHeader(500)
w.WriteJson(map[string]string{"error": fmt.Sprintf("Error: %s", err)})
}
w.WriteJson(responseUserData{user.Nickname, tokenString, user.Role})
} else {
w.WriteHeader(400)
w.WriteJson(map[string]string{"error": "email or password incorrect"})
}
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:45,代码来源:auth_controller.go
示例6: CategorysController
func CategorysController(w app.ResponseWriter, r *app.Request) {
category := models.Category{}
categorys := category.All()
w.WriteJson(categorys)
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:6,代码来源:category_controller.go
示例7: OwnerController
func OwnerController(w app.ResponseWriter, r *app.Request) {
user := models.User{}
user.Find("[email protected]")
user.Skills = user.GetSkills()
w.WriteJson(user)
}
开发者ID:chinakyc,项目名称:AgBlog,代码行数:6,代码来源:owner_controller.go
注:本文中的github.com/chinakyc/AgBlog/app.ResponseWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论