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


Golang GoWeb.Context类代码示例

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


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

示例1: Create

func (cr *PeopleController) Create(cx *goweb.Context) {

	// create a new appengine context
	gaerecords.CreateAppEngineContext(cx.Request)

	// create a new person
	person := People.New()

	// get the fields from the HTTP request
	var name string = cx.Request.FormValue("name")
	age, _ := strconv.Atoi64(cx.Request.FormValue("age"))

	// set the fields
	person.
		SetString("name", name).
		SetInt64("age", age)

	// save it
	err := person.Put()

	if err == nil {

		// success - redirect to see this person
		cx.RespondWithLocation(fmt.Sprint("/people/", person.ID()))

	} else {

		// failed - write the error
		cx.ResponseWriter.Write([]byte(fmt.Sprintf("Error: %v", err)))

	}

}
开发者ID:matryer,项目名称:gae-records,代码行数:33,代码来源:people_controller.go

示例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)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:22,代码来源:category.go

示例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))
	}
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:22,代码来源:article.go

示例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})
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:23,代码来源:comment.go

示例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)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:24,代码来源:search.go

示例6: Delete

func (cr *PeopleController) Delete(id string, cx *goweb.Context) {

	// create a new appengine context
	gaerecords.CreateAppEngineContext(cx.Request)

	// get the person ID from the URL
	personID, _ := strconv.Atoi64(id)

	// load the person
	person, _ := People.Find(personID)

	// delete the person
	person.Delete()

	// send them on their way
	cx.RespondWithLocation("/people")

}
开发者ID:matryer,项目名称:gae-records,代码行数:18,代码来源:people_controller.go

示例7: CallWordpressApi

/**
 * Roep de wordpress API aan
 *
 * @author A. Glansbeek en P. Kompier
 * @params *goweb.Context Context van goweb
 * @params interface De struct waarin json opgeslagen wordt
 * @params string functie naam van API wordpress
 * @params map[string]string map waarin params staan
 */
func CallWordpressApi(cx *goweb.Context, v interface{}, callfunction string, params map[string]string) {
	var contents []uint8

	url := createURL(callfunction, params)
	c := appengine.NewContext(cx.GetRequest())
	client := urlfetch.Client(c)
	response, err := client.Get(url)

	u := user.Current(c)
	var name string
	if u == nil {
		name = "Gast"
	} else {
		name = u.String()
	}

	data.SaveLog(url, name, cx.GetRequest())

	// Error check
	if err != nil {
		cx.RespondWithErrorMessage("Kan geen verbinding maken met de wordpress webservice", http.StatusBadRequest)
		return
	} else {
		// Aan het einde van deze functie sluit response
		defer response.Body.Close()

		// Maak van de content bytes
		contents, err = ioutil.ReadAll(response.Body)

		// Error check
		if err != nil {
			cx.RespondWithErrorMessage("Kan response niet lezen", http.StatusBadRequest)
			return
		}
	}

	err = json.Unmarshal(contents, v)

	// Error check
	if err != nil {
		cx.RespondWithErrorMessage("Kan json niet parsen err: "+err.String(), http.StatusBadRequest)
		return
	}
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:53,代码来源:communication.go

示例8: 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)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:43,代码来源:article.go

示例9: 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()
	}

}
开发者ID:nihao,项目名称:goweb,代码行数:11,代码来源:main.go

示例10: Read

func (cr *CommentController) Read(id string, cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusForbidden)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:3,代码来源:comment.go

示例11: UpdateMany

func (cr *CommentController) UpdateMany(cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusForbidden)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:3,代码来源:comment.go

示例12: Update

func (cr *CategoryController) Update(id string, cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusForbidden)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:3,代码来源:category.go

示例13: DeleteMany

func (cr *PeopleController) DeleteMany(cx *goweb.Context) {
	cx.RespondWithNotImplemented()
}
开发者ID:matryer,项目名称:gae-records,代码行数:3,代码来源:people_controller.go

示例14: Create

func (cr *SearchController) Create(cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusForbidden)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:3,代码来源:search.go

示例15: DeleteMany

func (cr *CategoryController) DeleteMany(cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusForbidden)
}
开发者ID:Alexandur,项目名称:ppopdr,代码行数:3,代码来源:category.go


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