本文整理汇总了Golang中github.com/coocood/qbs.Qbs.Rollback方法的典型用法代码示例。如果您正苦于以下问题:Golang Qbs.Rollback方法的具体用法?Golang Qbs.Rollback怎么用?Golang Qbs.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coocood/qbs.Qbs
的用法示例。
在下文中一共展示了Qbs.Rollback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HandlePanic
//HandlePanic rolls back the transiction provided and then panics again.
func (self *QbsDefaultOrmTransactionPolicy) HandlePanic(tx *qbs.Qbs, err interface{}) (interface{}, error) {
log.Printf("got panic, rolling back and returning 500 to client (%v)\n", err)
if rerr := tx.Rollback(); rerr != nil {
panic(rerr)
}
return nil, HTTPError(http.StatusInternalServerError, fmt.Sprintf("panic: %v", err))
}
示例2: HandleResult
//HandleResult determines whether or not the transaction provided should be rolled
//back or if it should be committed. It rolls back when the result value is
//a non-http error, if it is an Error and the status code is >= 400.
func (self *QbsDefaultOrmTransactionPolicy) HandleResult(tx *qbs.Qbs, value interface{}, err error) (interface{}, error) {
if err != nil {
switch e := err.(type) {
case *Error:
if e.StatusCode >= 400 {
rerr := tx.Rollback()
if rerr != nil {
return nil, rerr
}
}
default:
rerr := tx.Rollback()
if rerr != nil {
return nil, rerr
}
return nil, HTTPError(http.StatusInternalServerError, fmt.Sprintf("%v", err))
}
} else {
if cerr := tx.Commit(); cerr != nil {
return nil, cerr
}
}
return value, err
}