本文整理汇总了Golang中GoWeb.Context.RespondWithData方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RespondWithData方法的具体用法?Golang Context.RespondWithData怎么用?Golang Context.RespondWithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoWeb.Context
的用法示例。
在下文中一共展示了Context.RespondWithData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
func (cr *MyAPIController) Read(id string, cx *goweb.Context) {
if id == "1" {
cx.RespondWithData(TestEntity{id, "Mat", 28})
} else if id == "2" {
cx.RespondWithData(TestEntity{id, "Laurie", 27})
} else {
cx.RespondWithNotFound()
}
}
示例2: ReadMany
/**
* Retourneer hoofd categorieen
*
* @author A. Glansbeek en P. Kompier
* @version 1.0
* @date 2011-12-18
*/
func (cr *CategoryController) ReadMany(cx *goweb.Context) {
var m structs.WordpressHeadCategory
models.CallWordpressApi(cx, &m, "get_category_index", nil)
var headCategories []structs.HeadCategory
for _, category := range m.Categories {
// Alleen parents 0 (dat is hoofd category)
if category.Parent == 0 {
headCategories = append(headCategories, structs.HeadCategory{category.Id, category.Title})
}
}
cx.RespondWithData(headCategories)
}
示例3: Read
/**
* GET artikel met id [1..n], retourneer een artikel
*
* @author A. Glansbeek en P. Kompier
* @version 1.0
* @date 2011-12-18
*/
func (cr *ArticleController) Read(id string, cx *goweb.Context) {
params := map[string]string{"post_id": id}
var m structs.WordpressPost
models.CallWordpressApi(cx, &m, "get_post", params)
if m.Post.Id == 0 {
var str []string
str = append(str, "Het opgevraagde id bestaat niet")
cx.Respond(nil, 202, str, cx)
} else {
cx.RespondWithData(createArticle(m.Post))
}
}
示例4: Create
/**
* Creert een nieuwe comment (tip)
*
* @author A. Glansbeek en P. Kompier
* @version 1.0
* @date 2011-12-18
*/
func (cr *CommentController) Create(cx *goweb.Context) {
reqValues := cx.GetReqData()
params := map[string]string{
"post_id": reqValues.Get("post_id"),
"name": reqValues.Get("name"),
"email": reqValues.Get("email"),
"content": reqValues.Get("content"),
}
var m structs.WordpressCommentResponse
models.CallWordpressApi(cx, &m, "submit_comment", params)
cx.RespondWithData(structs.TipResponse{m.Status})
}
示例5: Read
/**
* Zoek functie!
*
* @author A. Glansbeek en P. Kompier
* @version 1.0
* @date 2012-01-06
*/
func (cr *SearchController) Read(input string, cx *goweb.Context) {
params := map[string]string{"search": input}
var m structs.WordpressPostMany
models.CallWordpressApi(cx, &m, "get_search_results", params)
var articles []structs.Article
for _, post := range m.Posts {
// Nieuw struct artikel
article := createArticle(post)
articles = append(articles, article)
}
cx.RespondWithData(articles)
}
示例6: ReadMany
/**
* Retourneer alle artikelen
*
* @author A. Glansbeek en P. Kompier
* @version 1.0
* @date 2011-12-18
*/
func (cr *ArticleController) ReadMany(cx *goweb.Context) {
var m structs.WordpressPostMany
// Als category_id is, pak dan alleen article van die category
if cx.PathParams["category_id"] != "" {
params := map[string]string{
"category_id": cx.PathParams["category_id"],
}
models.CallWordpressApi(cx, &m, "get_category_posts", params)
} else {
models.CallWordpressApi(cx, &m, "get_recent_posts", nil)
}
var mapper = make(map[string][]structs.Article)
for _, post := range m.Posts {
// Nieuw struct artikel
article := createArticle(post)
// Zet het artikel in de goede category
_, present := mapper[article.Category]
if present {
mapper[article.Category] = append(mapper[article.Category], article)
} else {
var articles []structs.Article
articles = append(articles, article)
mapper[article.Category] = articles
}
}
cx.RespondWithData(mapper)
}
示例7: UpdateMany
func (cr *MyAPIController) UpdateMany(cx *goweb.Context) {
cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
示例8: Update
func (cr *MyAPIController) Update(id string, cx *goweb.Context) {
cx.RespondWithData(TestEntity{id, "Mat", 28})
}
示例9: ReadMany
func (cr *MyAPIController) ReadMany(cx *goweb.Context) {
cx.RespondWithData([]TestEntity{TestEntity{"1", "Mat", 28}, TestEntity{"2", "Laurie", 27}})
}