本文整理汇总了Golang中github.com/ursiform/bear.Context.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Get方法的具体用法?Golang Context.Get怎么用?Golang Context.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ursiform/bear.Context
的用法示例。
在下文中一共展示了Context.Get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sessionVerify
func (app *router) sessionVerify(ctx *bear.Context) {
_, ok := ctx.Get(forest.SessionID).(string)
if !ok {
ctx.Set(forest.Error, errors.New("sessionVerify failed"))
app.Ware("ServerError")(ctx)
return
} else {
ctx.Next()
}
}
示例2: sessionDelIntercept
func (app *router) sessionDelIntercept(ctx *bear.Context) {
sessionID := ctx.Get(forest.SessionID).(string)
if sessionID == sessionIDWithSelfDestruct {
ctx.Set(forest.SessionID, nil)
}
if sessionID == sessionIDWithUserDestruct {
ctx.Set(forest.SessionUserID, nil)
}
ctx.Next()
}
示例3: safeErrorMessage
func safeErrorMessage(app *forest.App, ctx *bear.Context,
friendly string) string {
if err, ok := ctx.Get(forest.SafeError).(error); ok && err != nil {
return err.Error()
} else if err, ok := ctx.Get(forest.Error).(error); ok && err != nil {
return safeErrorFilter(app, err, friendly).Error()
} else {
return friendly
}
}
示例4: Marshal
func (manager *sessionManager) Marshal(ctx *bear.Context) ([]byte, error) {
sessionID := ctx.Get(forest.SessionID).(string)
if sessionID == sessionIDWithMarshalError {
return nil, errors.New("manager.Marshal error")
}
if sessionID == sessionIDWithSelfDestruct {
ctx.Set(forest.SessionID, nil)
}
if sessionID == sessionIDWithUserDestruct {
ctx.Set(forest.SessionUserID, nil)
}
return []byte(sessionUserJSON), nil
}
示例5: Create
func (manager *sessionManager) Create(sessionID string, userID string,
userJSON string, ctx *bear.Context) error {
testError, ok := ctx.Get("testerror").(bool)
if !ok {
testError = false
}
if testError {
return errors.New("manager.Create error")
} else {
ctx.Set(forest.SessionID, sessionID)
ctx.Set(forest.SessionUserID, userID)
return nil
}
}