本文整理匯總了Golang中github.com/imeoer/bamboo-api/ink.Context.TokenGet方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.TokenGet方法的具體用法?Golang Context.TokenGet怎麽用?Golang Context.TokenGet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/imeoer/bamboo-api/ink.Context
的用法示例。
在下文中一共展示了Context.TokenGet方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UserConfig
func UserConfig(ctx *ink.Context) {
defer exceptHandle(ctx)
userId := ctx.TokenGet("id").(string)
key := getParam(ctx, "key").(string)
value := getParam(ctx, "value").(string)
switch key {
case "mail":
if !validType("mail", value) {
panic("郵箱格式不正確")
}
if userExist(value) {
panic("賬戶已被使用")
}
case "name":
if !validate("[A-Za-z0-9_]+", value) {
panic("賬戶名稱隻接受字母數字下劃線")
}
case "nick":
case "motto":
case "avatar": // base64 encode
case "link":
default:
panic("要更新的選項不存在")
}
if userConfig(userId, key, value) {
returnRet(ctx, true, nil)
return
}
panic("更新失敗,內部錯誤")
}
示例2: ArticleFavarite
func ArticleFavarite(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
articleId := getParam(ctx, "articleId").(string)
isFavarite := getParam(ctx, "favarite").(bool)
ret := articleFavarite(userId, articleId, isFavarite)
returnRet(ctx, ret, isFavarite)
}
示例3: ArticleLike
func ArticleLike(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
articleId := getParam(ctx, "articleId").(string)
isLike := getParam(ctx, "like").(bool)
ret := articleLike(userId, articleId, isLike)
returnRet(ctx, ret, isLike)
}
示例4: CommentAdd
func CommentAdd(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
articleId := getParam(ctx, "articleId").(string)
content := getParam(ctx, "content").(string)
ret := articleCommentAdd(userId, articleId, content)
returnRet(ctx, ret, nil)
}
示例5: UserTimeline
func UserTimeline(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
ret := userTimeline(userId)
if ret != nil {
returnRet(ctx, true, ret)
return
}
returnRet(ctx, false, "獲取動態失敗")
}
示例6: UserCheckToken
func UserCheckToken(ctx *ink.Context) {
userId := ctx.TokenGet("id")
fmt.Println(userId)
if userId != nil {
returnRet(ctx, true, nil)
return
}
returnRet(ctx, false, nil)
}
示例7: ArticleRemove
func ArticleRemove(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
articleId := getParam(ctx, "articleId").(string)
ret := articleRemove(userId, articleId)
if ret {
returnRet(ctx, true, nil)
return
}
returnRet(ctx, false, "文章刪除失敗")
}
示例8: CircleFocus
func CircleFocus(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
circle := getParam(ctx, "circle").(string)
isFocus := getParam(ctx, "focus").(bool)
if !isInArray(circle, CIRCLES) {
returnRet(ctx, false, "指定圈子錯誤")
return
}
ret := circleFocus(userId, circle, isFocus)
returnRet(ctx, ret, isFocus)
}
示例9: ArticleUpdate
func ArticleUpdate(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
articleId := getParam(ctx, "articleId").(string)
articleTitle := getParam(ctx, "title").(string)
articleContent := getParam(ctx, "content").(string)
articleCircles := getParam(ctx, "circles").([]interface{})
articlePublic := getParam(ctx, "public").(bool)
for _, circle := range articleCircles {
if !isInArray(circle.(string), CIRCLES) {
returnRet(ctx, false, "指定圈子錯誤")
return
}
}
ret := articleUpdate(userId, articleId, articleTitle, articleContent, articleCircles, articlePublic)
if len(ret) != 0 {
returnRet(ctx, true, ret)
return
}
returnRet(ctx, false, "文章更新失敗")
}
示例10: ArticleList
func ArticleList(ctx *ink.Context) {
userId := ctx.TokenGet("id").(string)
filter := getParam(ctx, "filter").(string) // ["private", "public", "favarite"]
if !isInArray(filter, []string{"private", "public", "favarite"}) {
returnRet(ctx, false, "指定過濾條件錯誤")
return
}
ret := articleList(userId, filter)
if ret != nil {
// for idx, item := range *ret {
// content := []rune(item.Content)
// fmt.Println(item.Content)
// if len(content) > 140 {
// (*ret)[idx].Content = string(content[0:140])
// }
// }
returnRet(ctx, true, *ret)
return
}
returnRet(ctx, true, "文章獲取失敗")
}
示例11: PreHandle
/* helper method */
func PreHandle(ctx *ink.Context) {
// auth check
path := ctx.Req.URL.Path
if path != "/user/login" && path != "/user/check_token" && path != "/article/get" && path != "/user/register" && path != "/user/page" {
userId := ctx.TokenGet("id")
if userId == nil {
returnRet(ctx, false, "權限驗證失敗")
ctx.Stop()
return
}
}
// parse request json data
if path != "/article/upload" {
decoder := json.NewDecoder(ctx.Req.Body)
data := make(Map)
err := decoder.Decode(&data)
if err != nil {
returnRet(ctx, false, "json parse error")
ctx.Stop()
return
}
ctx.Ware["data"] = data
}
}