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


Golang pat.Param函数代码示例

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


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


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