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

Golang echo.Context类代码示例

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

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



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

示例1: createUser

func createUser(c *echo.Context) error {
	u := new(user)
	if err := c.Bind(u); err != nil {
		return err
	}
	users[u.ID] = *u
	return c.JSON(http.StatusCreated, u)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:8,代码来源:server.go


示例2: errorHandler

func errorHandler(err error, c *echo.Context) {
	code := http.StatusInternalServerError
	msg := http.StatusText(code)
	if he, ok := err.(*echo.HTTPError); ok {
		code = he.Code()
		msg = he.Error()
	}
	c.Response().Header().Set("Content-Type", "text/plain; charset=utf-8")
	c.Response().WriteHeader(code)
	c.Response().Write([]byte(msg))
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:11,代码来源:api.go


示例3: addLabel

//
// POST /library/labels
//
func addLabel(c *echo.Context) error {
	name := strings.TrimPrefix(form(c, "name"), "label/")
	if name == "" {
		return c.String(400, "Name too short")
	}

	label := Label{
		Name:     name,
		Content:  form(c, "content"),
		Expanded: form(c, "expanded") == "true",
	}

	user := c.Get("user").(*User)
	err := store.SaveLabel(&label, user.ID)
	if err == ErrLabelExists {
		return c.String(409, "Existing label")
	} else if err != nil {
		return err
	}

	return c.JSON(200, addedLabel{
		ID:   label.ID,
		Name: label.Name,
	})
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:28,代码来源:labels.go


示例4: removeCast

//
// DELETE /library/casts/:id
//
func removeCast(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	user := c.Get("user").(*User)
	user, err = store.RemoveSubscription(user.ID, id)
	authCache.set(c.Get("token").(string), user)
	return err
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:14,代码来源:casts.go


示例5: getNewEpisodes

//
// GET /library/newepisodes
//
func getNewEpisodes(c *echo.Context) error {
	now := time.Now().Unix()
	user := c.Get("user").(*User)
	since := c.Request().URL.Query().Get("since")
	if since == "" {
		return c.JSON(200, newEpisodes{
			Timestamp: now,
			Episodes:  store.GetEpisodesSince(0, user.Subscriptions),
		})
	}

	ts, err := strconv.ParseInt(since, 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	return c.JSON(200, newEpisodes{
		Timestamp: now,
		Episodes:  store.GetEpisodesSince(ts, user.Subscriptions),
	})
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:24,代码来源:episodes.go


示例6: removeSetting

//
// DELETE /account/settings/:id
//
func removeSetting(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	user := c.Get("user").(*User)
	err = store.RemoveSetting(id, user.ID)
	if err == ErrSettingNotFound {
		return c.String(404, "Setting not found")
	}

	return err
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:17,代码来源:account.go


示例7: getEpisode

//
// GET /library/episode/:id
//
func getEpisode(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	return c.JSON(200, store.GetEpisode(id))
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:11,代码来源:episodes.go


示例8: login

//
// POST /account/login
//
func login(c *echo.Context) error {
	if !formContains(c, "username", "password", "uuid", "clientname") {
		return echo.NewHTTPError(400)
	}

	user := store.GetUser(form(c, "username"))
	if user == nil {
		return echo.NewHTTPError(401)
	}

	if correctPassword(user.Password, form(c, "password")) {
		uuid := form(c, "uuid")
		for _, client := range user.Clients {
			if uuid == client.UUID {
				return c.JSON(200, token{client.Token})
			}
		}

		t, err := createToken(32)
		if err != nil {
			return err
		}

		err = store.AddClient(user.ID, &Client{
			Token: t,
			UUID:  uuid,
			Name:  form(c, "clientname"),
		})
		if err != nil {
			return err
		}

		return c.JSON(200, token{t})
	}

	return echo.NewHTTPError(401)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:40,代码来源:account.go


示例9: removeLabel

//
// DELETE /library/labels/:id
//
func removeLabel(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	user := c.Get("user").(*User)
	return store.RemoveLabel(id, user.ID)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:12,代码来源:labels.go


示例10: updateUser

func updateUser(c *echo.Context) error {
	u := new(user)
	if err := c.Bind(u); err != nil {
		return err
	}
	id, _ := strconv.Atoi(c.Param("id"))
	users[id].Name = u.Name
	return c.JSON(http.StatusOK, users[id])
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:9,代码来源:server.go


示例11: addEvents

//
// POST /library/events
//
func addEvents(c *echo.Context) error {
	data := form(c, "json")
	if data == "" {
		return c.NoContent(400)
	}

	events := []Event{}
	err := json.Unmarshal([]byte(data), &events)
	if err != nil {
		return c.NoContent(400)
	}

	user := c.Get("user").(*User)
	uuid := c.Get("uuid").(string)
	return store.AddEvents(events, user.ID, uuid)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:19,代码来源:events.go


示例12: setSettings

//
// POST /account/settings
//
func setSettings(c *echo.Context) error {
	data := form(c, "json")
	if data == "" {
		return c.NoContent(400)
	}

	settings := []Setting{}
	err := json.Unmarshal([]byte(data), &settings)
	if err != nil {
		return c.NoContent(400)
	}

	user := c.Get("user").(*User)
	uuid := c.Get("uuid").(string)
	return store.SaveSettings(settings, user.ID, uuid)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:19,代码来源:account.go


示例13: addCast

//
// POST /library/casts
//
func addCast(c *echo.Context) error {
	user := c.Get("user").(*User)
	url := form(c, "feedurl")
	cast := store.GetCastByURL(url)
	if cast == nil {
		cast = <-crawl.fetch(url)
		if cast == nil {
			return c.String(500, "Could not fetch feed")
		}
	}

	user, err := store.AddSubscription(user.ID, cast.ID)
	if err != nil && err != ErrSubscriptionExists {
		return err
	}

	authCache.set(c.Get("token").(string), user)

	return c.JSON(200, cast)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:23,代码来源:casts.go


示例14: updateLabel

//
// PUT /library/labels/:id
//
func updateLabel(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	label := store.GetLabel(id)
	if label == nil {
		return c.String(404, "Label not found")
	}

	if name := form(c, "name"); name != "" {
		label.Name = name
	}
	if content := form(c, "content"); content != "" {
		label.Content = content
	}
	if expanded := form(c, "expanded"); expanded != "" {
		label.Expanded = expanded == "true"
	}

	user := c.Get("user").(*User)
	return store.SaveLabel(label, user.ID)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:27,代码来源:labels.go


示例15: renameCast

//
// PUT /library/casts/:id
//
func renameCast(c *echo.Context) error {
	id, err := strconv.ParseUint(c.Param("id"), 10, 64)
	if err != nil {
		return c.NoContent(400)
	}

	cast := store.GetCast(id)
	if cast == nil {
		return c.String(404, "Cast not found")
	}

	prev := cast.Name
	cast.Name = form(c, "name")
	if cast.Name != prev {
		return store.SaveCast(cast)
	}

	return nil
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:22,代码来源:casts.go


示例16: getUser

func getUser(c *echo.Context) error {
	id, _ := strconv.Atoi(c.Param("id"))
	return c.JSON(http.StatusOK, users[id])
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:4,代码来源:server.go


示例17: getCasts

//
// GET /library/casts
//
func getCasts(c *echo.Context) error {
	user := c.Get("user").(*User)
	return c.JSON(200, store.GetCastsByID(user.Subscriptions))
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:7,代码来源:casts.go


示例18: hello

// Handler
func hello(c *echo.Context) error {
	return c.String(http.StatusOK, "Hello, World!\n")
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:4,代码来源:server.go


示例19: form

func form(c *echo.Context, key string) string {
	return c.Request().FormValue(key)
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:3,代码来源:util.go


示例20: welcome

func welcome(c *echo.Context) error {
	return c.Render(http.StatusOK, "welcome", "Joe")
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:3,代码来源:server.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-23
下一篇:
Golang bolt.Tx类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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