本文整理匯總了Golang中github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/labstack/echo.Context.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Get方法的具體用法?Golang Context.Get怎麽用?Golang Context.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.Get方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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,
})
}
示例2: 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)
}
示例3: 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
}
示例4: 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
}
示例5: 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)
}
示例6: 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)
}
示例7: 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)
}
示例8: 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),
})
}
示例9: 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)
}
示例10: getEvents
//
// GET /library/events
//
func getEvents(c *echo.Context) error {
now := time.Now().Unix()
var err error
var ts uint64
since := c.Request().URL.Query().Get("since")
if since != "" {
ts, err = strconv.ParseUint(since, 10, 64)
if err != nil {
return c.NoContent(400)
}
}
user := c.Get("user").(*User)
uuid := ""
excludeSelf := c.Request().URL.Query().Get("exclude_self")
if excludeSelf == "true" {
uuid = c.Get("uuid").(string)
}
return c.JSON(200, events{
Timestamp: now,
Events: store.GetEvents(user.ID, ts, uuid),
})
}
示例11: getCasts
//
// GET /library/casts
//
func getCasts(c *echo.Context) error {
user := c.Get("user").(*User)
return c.JSON(200, store.GetCastsByID(user.Subscriptions))
}
示例12: getSettings
//
// GET /account/settings
//
func getSettings(c *echo.Context) error {
user := c.Get("user").(*User)
uuid := c.Get("uuid").(string)
return c.JSON(200, store.GetSettings(user.ID, uuid))
}
示例13: getLabels
//
// GET /library/labels
//
func getLabels(c *echo.Context) error {
user := c.Get("user").(*User)
return c.JSON(200, store.GetLabels(user.ID))
}