本文整理汇总了Golang中github.com/ursiform/bear.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
}
示例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: 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()
}
}
示例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
}
}
示例6: sessionCreateError
func (app *router) sessionCreateError(ctx *bear.Context) {
ctx.Set("testerror", true).Next()
}
示例7: initPostParse
func (app *router) initPostParse(ctx *bear.Context) {
ctx.Set(forest.Body, new(postBody)).Next()
}
示例8: customSafeErrorFilterSuccess
func (app *router) customSafeErrorFilterSuccess(ctx *bear.Context) {
ctx.Set(forest.Error, errors.New(customSafeErrorMessage))
app.Ware("ServerError")(ctx)
}
示例9: authenticate
func (app *router) authenticate(ctx *bear.Context) {
ctx.Set(forest.SessionID, sessionIDExistent)
ctx.Set(forest.SessionUserID, sessionUserID)
ctx.Next()
}
示例10: CreateEmpty
func (manager *sessionManager) CreateEmpty(sessionID string,
ctx *bear.Context) {
ctx.Set(forest.SessionID, sessionID)
}