当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.RespondWithData方法代码示例

本文整理汇总了Golang中github.com/stretchrcom/goweb/goweb.Context.RespondWithData方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RespondWithData方法的具体用法?Golang Context.RespondWithData怎么用?Golang Context.RespondWithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/stretchrcom/goweb/goweb.Context的用法示例。


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

示例1: Read

func (cr *TeamAPIController) 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()
	}

}
开发者ID:robxu9,项目名称:reservoir,代码行数:11,代码来源:team.go

示例2: Read

// Handle GET requests
func (cr *OtterAPIController) Read(id string, cx *goweb.Context) {
	var otter Otter
	// TODO rewrite using a tohva stored in the session
	var err error = nil
	//_, err := cr.Db.Retrieve(id, &otter)
	if err != nil {
		cx.RespondWithData(otter)
	} else {
		cx.RespondWithNotFound()
	}
}
开发者ID:beer-root,项目名称:toris,代码行数:12,代码来源:handlers.go

示例3: Read

func (cr *Controller) Read(id string, cx *goweb.Context) {
	log.Printf("Read a article id=%s", id)
	c := cr.db.C(COLLECTION)
	var article Article
	if err := c.FindId(id).One(&article); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Read article id=%s", id)
	cx.RespondWithData(article)
}
开发者ID:rails0330,项目名称:goweb,代码行数:13,代码来源:controller.go

示例4: Create

func (cr *Controller) Create(cx *goweb.Context) {
	log.Println("Creating a article...")
	c := cr.db.C(COLLECTION)

	var article Article
	decoder := new(goweb.JsonRequestDecoder)
	decoder.Unmarshal(cx, &article)

	article.Id = bson.NewObjectId().Hex()

	if err := c.Insert(&article); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Created diary id=%s", article.Id)
	cx.RespondWithData(article)
}
开发者ID:rails0330,项目名称:goweb,代码行数:19,代码来源:controller.go

示例5: ReadMany

func (cr *Controller) ReadMany(cx *goweb.Context) {
	log.Println("Read all articles...")
	c := cr.db.C(COLLECTION)
	count, err := c.Count()
	if err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	articles := make([]*Article, count)
	if err := c.Find(nil).All(&articles); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Read all %d articles", count)
	cx.RespondWithData(articles)
}
开发者ID:rails0330,项目名称:goweb,代码行数:20,代码来源:controller.go

示例6: UpdateMany

func (cr *TeamAPIController) UpdateMany(cx *goweb.Context) {
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
开发者ID:robxu9,项目名称:reservoir,代码行数:3,代码来源:team.go

示例7: Update

func (cr *TeamAPIController) Update(id string, cx *goweb.Context) {
	cx.RespondWithData(TestEntity{id, "Mat", 28})
}
开发者ID:robxu9,项目名称:reservoir,代码行数:3,代码来源:team.go

示例8: ReadMany

func (cr *TeamAPIController) ReadMany(cx *goweb.Context) {
	cx.RespondWithData([]TestEntity{TestEntity{"1", "Mat", 28}, TestEntity{"2", "Laurie", 27}})
}
开发者ID:robxu9,项目名称:reservoir,代码行数:3,代码来源:team.go

示例9: Create

func (cr *CreateAPIController) Create(cx *goweb.Context) {
	cx.PathParams["apikey"]
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
开发者ID:robxu9,项目名称:reservoir,代码行数:4,代码来源:create.go

示例10: Create

// Handle POST requests
func (cr *OtterAPIController) Create(cx *goweb.Context) {
	otter := NewOtter()
	// TODO rewrite using a tohva stored in the session
	// cr.Db.Insert(otter)
	cx.RespondWithData(otter)
}
开发者ID:beer-root,项目名称:toris,代码行数:7,代码来源:handlers.go

示例11: Create

func (cr *UserAPIController) Create(cx *goweb.Context) {
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
开发者ID:robxu9,项目名称:reservoir,代码行数:3,代码来源:user.go


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