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

Golang pat.Param函数代码示例

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

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



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

示例1: DeleteLine

func (c *Controller) DeleteLine(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	convoID := pat.Param(ctx, "conversation")
	lineID := pat.Param(ctx, "line")

	if err := c.repo.DeleteLine(userID, convoID, lineID); err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusNoContent)
}
开发者ID:antifuchs,项目名称:saypi,代码行数:11,代码来源:say.go


示例2: DeleteLine

func (c *Controller) DeleteLine(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	convoID := pat.Param(ctx, "conversation")
	lineID := pat.Param(ctx, "line")

	if err := c.repo.DeleteLine(userID, convoID, lineID); err == errRecordNotFound {
		respond.NotFound(ctx, w, r)
	} else if err != nil {
		respond.InternalError(ctx, w, err)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
开发者ID:metcalf,项目名称:saypi,代码行数:14,代码来源:say.go


示例3: bookByISBN

func bookByISBN(s *mgo.Session) goji.HandlerFunc {
	return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		session := s.Copy()
		defer session.Close()

		isbn := pat.Param(ctx, "isbn")

		c := session.DB("store").C("books")

		var book Book
		err := c.Find(bson.M{"isbn": isbn}).One(&book)
		if err != nil {
			ErrorWithJSON(w, "Database error", http.StatusInternalServerError)
			log.Println("Failed find book: ", err)
			return
		}

		if book.ISBN == "" {
			ErrorWithJSON(w, "Book not found", http.StatusNotFound)
			return
		}

		respBody, err := json.MarshalIndent(book, "", "  ")
		if err != nil {
			log.Fatal(err)
		}

		ResponseWithJSON(w, respBody, http.StatusOK)
	}
}
开发者ID:upitau,项目名称:goinbigdata,代码行数:30,代码来源:main.go


示例4: updateBook

func updateBook(s *mgo.Session) goji.HandlerFunc {
	return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		session := s.Copy()
		defer session.Close()

		isbn := pat.Param(ctx, "isbn")

		var book Book
		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&book)
		if err != nil {
			ErrorWithJSON(w, "Incorrect body", http.StatusBadRequest)
			return
		}

		c := session.DB("store").C("books")

		err = c.Update(bson.M{"isbn": isbn}, &book)
		if err != nil {
			switch err {
			default:
				ErrorWithJSON(w, "Database error", http.StatusInternalServerError)
				log.Println("Failed update book: ", err)
				return
			case mgo.ErrNotFound:
				ErrorWithJSON(w, "Book not found", http.StatusNotFound)
				return
			}
		}

		w.WriteHeader(http.StatusNoContent)
	}
}
开发者ID:upitau,项目名称:goinbigdata,代码行数:33,代码来源:main.go


示例5: deleteBook

func deleteBook(s *mgo.Session) goji.HandlerFunc {
	return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		session := s.Copy()
		defer session.Close()

		isbn := pat.Param(ctx, "isbn")

		c := session.DB("store").C("books")

		err := c.Remove(bson.M{"isbn": isbn})
		if err != nil {
			switch err {
			default:
				ErrorWithJSON(w, "Database error", http.StatusInternalServerError)
				log.Println("Failed delete book: ", err)
				return
			case mgo.ErrNotFound:
				ErrorWithJSON(w, "Book not found", http.StatusNotFound)
				return
			}
		}

		w.WriteHeader(http.StatusNoContent)
	}
}
开发者ID:upitau,项目名称:goinbigdata,代码行数:25,代码来源:main.go


示例6: HandleCard

func (a *API) HandleCard(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	card, err := a.c.GetCard(ctx, pat.Param(ctx, "id"))
	if err != nil {
		JSON(w, http.StatusNotFound, Errors("Card not found"))
		return
	}
	JSON(w, http.StatusOK, card)
}
开发者ID:kyleconroy,项目名称:deckbrew,代码行数:8,代码来源:handler.go


示例7: HandleSet

func (a *API) HandleSet(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	card, err := a.c.GetSet(ctx, pat.Param(ctx, "id"))

	if err != nil {
		JSON(w, http.StatusNotFound, Errors("Set not found"))
	} else {
		JSON(w, http.StatusOK, card)
	}
}
开发者ID:kyleconroy,项目名称:deckbrew,代码行数:9,代码来源:handler.go


示例8: setReadNotifications

func setReadNotifications(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	id := pat.Param(ctx, "id")
	smt, err := database.Prepare("UPDATE notification SET read=? WHERE id=?")
	checkErr(err, "setReadNotifications")
	defer smt.Close()
	_, err = smt.Exec(true, id)
	checkErr(err, "setReadNotifications")
	writeJson(w, ResponseStatus{Status: "ok"})
}
开发者ID:mdebelle,项目名称:macha,代码行数:9,代码来源:notifications.go


示例9: toManyHandler

// GET /resources/:id/(relationships/)<resourceType>s
func (res *Resource) toManyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, storage store.ToMany) {
	id := pat.Param(ctx, "id")

	list, err := storage(ctx, id)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendHandler(ctx, w, r, err)
		return
	}

	SendHandler(ctx, w, r, list)
}
开发者ID:derekdowling,项目名称:go-json-spec-handler,代码行数:12,代码来源:resource.go


示例10: deleteHandler

// DELETE /resources/:id
func (res *Resource) deleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, storage store.Delete) {
	id := pat.Param(ctx, "id")

	err := storage(ctx, id)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendAndLog(ctx, w, r, err)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
开发者ID:samikoskinen,项目名称:go-json-spec-handler,代码行数:12,代码来源:resource.go


示例11: actionHandler

// All HTTP Methods for /resources/:id/<mutate>
func (res *Resource) actionHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, storage store.Get) {
	id := pat.Param(ctx, "id")

	response, err := storage(ctx, id)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendAndLog(ctx, w, r, err)
		return
	}

	SendAndLog(ctx, w, r, response)
}
开发者ID:samikoskinen,项目名称:go-json-spec-handler,代码行数:12,代码来源:resource.go


示例12: GetUser

func (c *Controller) GetUser(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	id := pat.Param(ctx, "id")
	if id == "" {
		panic("GetUser called without an `id` URL Var")
	}

	if c.getUser(id) != nil {
		w.WriteHeader(204)
	} else {
		respond.NotFound(ctx, w, r)
	}
}
开发者ID:antifuchs,项目名称:saypi,代码行数:12,代码来源:auth.go


示例13: GetLine

func (c *Controller) GetLine(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	convoID := pat.Param(ctx, "conversation")
	lineID := pat.Param(ctx, "line")

	line, err := c.repo.GetLine(userID, convoID, lineID)
	if err != nil {
		panic(err)
	}
	if line == nil {
		respond.NotFound(ctx, w, r)
		return
	}

	line.Output, err = c.renderLine(line)
	if err != nil {
		panic(err)
	}

	respond.Data(ctx, w, http.StatusOK, line)
}
开发者ID:antifuchs,项目名称:saypi,代码行数:21,代码来源:say.go


示例14: SetMood

func (c *Controller) SetMood(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	name := pat.Param(ctx, "mood")

	var mood Mood
	r.ParseForm()
	err := decoder.Decode(&mood, r.PostForm)
	if err != nil {
		respond.InternalError(ctx, w, err)
		return
	}

	mood.Eyes = strings.Replace(mood.Eyes, "\x00", "", -1)
	mood.Tongue = strings.Replace(mood.Tongue, "\x00", "", -1)

	var uerr usererrors.InvalidParams
	if !(mood.Eyes == "" || utf8.RuneCountInString(mood.Eyes) == 2) {
		uerr = append(uerr, usererrors.InvalidParamsEntry{
			Params:  []string{"eyes"},
			Message: "must be a string containing two characters",
		})
	}

	if !(mood.Tongue == "" || utf8.RuneCountInString(mood.Tongue) == 2) {
		uerr = append(uerr, usererrors.InvalidParamsEntry{
			Params:  []string{"tongue"},
			Message: "must be a string containing two characters",
		})
	}

	if uerr != nil {
		respond.UserError(ctx, w, http.StatusBadRequest, uerr)
		return
	}

	mood.Name = name
	mood.UserDefined = true

	err = c.repo.SetMood(userID, &mood)
	if err == errBuiltinMood {
		respond.UserError(ctx, w, http.StatusBadRequest, usererrors.ActionNotAllowed{
			Action: fmt.Sprintf("update built-in mood %s", name),
		})
		return
	} else if err != nil {
		respond.InternalError(ctx, w, err)
		return
	}

	respond.Data(ctx, w, http.StatusOK, mood)
}
开发者ID:metcalf,项目名称:saypi,代码行数:51,代码来源:say.go


示例15: GetMood

func (c *Controller) GetMood(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	name := pat.Param(ctx, "mood")

	res, err := c.repo.GetMood(userID, name)
	if err != nil {
		panic(err)
	}
	if res == nil {
		respond.NotFound(ctx, w, r)
		return
	}

	respond.Data(ctx, w, http.StatusOK, res)
}
开发者ID:antifuchs,项目名称:saypi,代码行数:15,代码来源:say.go


示例16: DeleteMood

func (c *Controller) DeleteMood(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	name := pat.Param(ctx, "mood")

	if err := c.repo.DeleteMood(userID, name); err == errBuiltinMood {
		respond.Error(ctx, w, http.StatusBadRequest, usererrors.ActionNotAllowed{
			Action: fmt.Sprintf("delete built-in mood %s", name),
		})
		return
	} else if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusNoContent)
}
开发者ID:antifuchs,项目名称:saypi,代码行数:15,代码来源:say.go


示例17: deleteUsersInterests

func deleteUsersInterests(ctx context.Context, w http.ResponseWriter, r *http.Request) {

	session, _ := store.Get(r, "session")
	if session.Values["connected"] != true {
		http.Redirect(w, r, "/", http.StatusNetworkAuthenticationRequired)
		return
	}

	id := pat.Param(ctx, "interestid")

	smt, err := database.Prepare("DELETE FROM userinterest WHERE interestid=? AND userid=?")
	checkErr(err, "deleteUsersInterests")
	defer smt.Close()
	_, err = smt.Exec(id, session.Values["UserInfo"].(UserData).Id)
	checkErr(err, "deleteUsersInterests")
	writeJson(w, ResponseStatus{Status: "ok"})

}
开发者ID:mdebelle,项目名称:macha,代码行数:18,代码来源:users.go


示例18: DeleteMood

func (c *Controller) DeleteMood(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID := mustUserID(ctx)
	name := pat.Param(ctx, "mood")

	if err := c.repo.DeleteMood(userID, name); err == errBuiltinMood {
		respond.UserError(ctx, w, http.StatusBadRequest, usererrors.ActionNotAllowed{
			Action: fmt.Sprintf("delete built-in mood %s", name),
		})
	} else if err == errRecordNotFound {
		respond.NotFound(ctx, w, r)
	} else if conflict, ok := err.(conflictErr); ok {
		respond.UserError(ctx, w, http.StatusBadRequest, usererrors.ActionNotAllowed{
			Action: fmt.Sprintf("delete a mood associated with %d conversation lines", len(conflict.IDs)),
		})
	} else if err != nil {
		respond.InternalError(ctx, w, err)
	} else {
		w.WriteHeader(http.StatusNoContent)
	}
}
开发者ID:metcalf,项目名称:saypi,代码行数:20,代码来源:say.go


示例19: patchHandler

// PATCH /resources/:id
func (res *Resource) patchHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, storage store.Update) {
	parsedObject, parseErr := jsh.ParseObject(r)
	if parseErr != nil && reflect.ValueOf(parseErr).IsNil() == false {
		SendHandler(ctx, w, r, parseErr)
		return
	}

	id := pat.Param(ctx, "id")
	if id != parsedObject.ID {
		SendHandler(ctx, w, r, jsh.InputError("Request ID does not match URL's", "id"))
		return
	}

	object, err := storage(ctx, parsedObject)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendHandler(ctx, w, r, err)
		return
	}

	SendHandler(ctx, w, r, object)
}
开发者ID:derekdowling,项目名称:go-json-spec-handler,代码行数:22,代码来源:resource.go


示例20: publicProfile

func publicProfile(ctx context.Context, w http.ResponseWriter, r *http.Request) {

	var user SimpleUser
	var c bool
	id, _ := strconv.ParseInt(pat.Param(ctx, "id"), 10, 64)

	session, _ := store.Get(r, "session")
	if session.Values["connected"] == true {
		c = true
		session.Options.MaxAge = 20
		session.Save(r, w)
	}

	smt, err := database.Prepare("SELECT user.username, user.birthdate FROM user WHERE id=?")
	checkErr(err, "publicProfile")
	var dob []uint8
	smt.QueryRow(id).Scan(&user.UserName, &dob)
	user.Id = id
	user.Bod = transformAge(dob)
	if c == false {
		renderTemplate(w, "publicProfile", &publicProfileView{
			Header: HeadData{
				Title:      "Profile",
				Stylesheet: []string{"publicProfile.css"}},
			Connection: false,
			Profile:    user})
		visitedProfile("unknown", id)
	} else {
		renderTemplate(w, "publicProfile", &publicProfileView{
			Header: HeadData{
				Title:      "Profile",
				Stylesheet: []string{"publicProfile.css"}},
			Connection: true,
			User:       session.Values["UserInfo"].(UserData),
			Profile:    user})
		visitedProfile(session.Values["UserInfo"].(UserData).UserName, id)
	}

}
开发者ID:mdebelle,项目名称:macha,代码行数:39,代码来源:users.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang buildlet.Client类代码示例发布时间:2022-05-28
下一篇:
Golang pat.Get函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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