Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorMessage2Error(errMsg string, err error) error
- func GetCurrentDBType() string
- func GetRestyClient() *resty.Client
- func GetRestyClient2(timeout time.Duration) *resty.Client
- func HTTPResp2DtmError(resp *resty.Response) error
- func MustGenGid(server string) string
- func Result2HttpJSON(result interface{}) (code int, res interface{})
- func SetBarrierTableName(tablename string)
- func SetCurrentDBType(dbType string)
- func TccGlobalTransaction(dtm string, gid string, tccFunc TccGlobalFunc) (rerr error)
- func TccGlobalTransaction2(dtm string, gid string, custom func(*Tcc), tccFunc TccGlobalFunc) (rerr error)
- func XaGlobalTransaction(server string, gid string, xaFunc XaGlobalFunc) error
- func XaGlobalTransaction2(server string, gid string, custom func(*Xa), xaFunc XaGlobalFunc) (rerr error)
- func XaLocalTransaction(qs url.Values, dbConf DBConf, xaFunc XaLocalFunc) error
- type BarrierBusiFunc
- type BranchBarrier
- func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error)
- func (bb *BranchBarrier) CallWithDB(db *sql.DB, busiCall BarrierBusiFunc) error
- func (bb *BranchBarrier) MongoCall(mc *mongo.Client, busiCall func(mongo.SessionContext) error) (rerr error)
- func (bb *BranchBarrier) MongoQueryPrepared(mc *mongo.Client) error
- func (bb *BranchBarrier) QueryPrepared(db *sql.DB) error
- func (bb *BranchBarrier) RedisCheckAdjustAmount(rd *redis.Client, key string, amount int, barrierExpire int) error
- func (bb *BranchBarrier) RedisQueryPrepared(rd *redis.Client, barrierExpire int) error
- func (bb *BranchBarrier) String() string
- type DB
- type DBConf
- type Msg
- func (s *Msg) Add(action string, postData interface{}) *Msg
- func (s *Msg) AddTopic(topic string, postData interface{}) *Msg
- func (s *Msg) BuildCustomOptions()
- func (s *Msg) DoAndSubmit(queryPrepared string, busiCall func(bb *BranchBarrier) error) error
- func (s *Msg) DoAndSubmitDB(queryPrepared string, db *sql.DB, busiCall BarrierBusiFunc) error
- func (s *Msg) Prepare(queryPrepared string) error
- func (s *Msg) SetDelay(delay uint64) *Msg
- func (s *Msg) Submit() error
- type Saga
- type Tcc
- type TccGlobalFunc
- type TransOptions
- type Xa
- type XaGlobalFunc
- type XaLocalFunc
Constants ¶
const ( // StatusPrepared status for global/branch trans status. // first step, tx preparation period StatusPrepared = "prepared" // StatusSubmitted status for global trans status. StatusSubmitted = "submitted" // StatusSucceed status for global/branch trans status. StatusSucceed = "succeed" // StatusFailed status for global/branch trans status. // NOTE: change global status to failed can stop trigger (Not recommended in production env) StatusFailed = "failed" // StatusAborting status for global trans status. StatusAborting = "aborting" // ResultSuccess for result of a trans/trans branch ResultSuccess = dtmimp.ResultSuccess // ResultFailure for result of a trans/trans branch ResultFailure = dtmimp.ResultFailure // ResultOngoing for result of a trans/trans branch ResultOngoing = dtmimp.ResultOngoing // DBTypeMysql const for driver mysql DBTypeMysql = dtmimp.DBTypeMysql // DBTypePostgres const for driver postgres DBTypePostgres = dtmimp.DBTypePostgres )
Variables ¶
var ErrDuplicated = dtmimp.ErrDuplicated
ErrDuplicated error of DUPLICATED for only msg if QueryPrepared executed before call. then DoAndSubmit return this error
var ErrFailure = dtmimp.ErrFailure
ErrFailure error for returned failure
var ErrOngoing = dtmimp.ErrOngoing
ErrOngoing error for returned ongoing
var MapFailure = dtmimp.MapFailure
MapFailure HTTP result of FAILURE
var MapSuccess = dtmimp.MapSuccess
MapSuccess HTTP result of SUCCESS
Functions ¶
func ErrorMessage2Error ¶
ErrorMessage2Error return an error fmt.Errorf("%s %w", errMsg, err) but trim out duplicate wrap eg. ErrorMessage2Error("an error. FAILURE", ErrFailure) return an error with message: "an error. FAILURE", no additional " FAILURE" added
func GetRestyClient ¶
func GetRestyClient() *resty.Client
GetRestyClient get the resty.Client for http request
func GetRestyClient2 ¶
GetRestyClient2 get the resty.Client with the specified timeout set
func HTTPResp2DtmError ¶
func HTTPResp2DtmError(resp *resty.Response) error
HTTPResp2DtmError translate a resty response to error compatible with version < v1.10
func Result2HttpJSON ¶
func Result2HttpJSON(result interface{}) (code int, res interface{})
Result2HttpJSON return the http code and json result if result is error, the return proper code, else return StatusOK
func SetBarrierTableName ¶
func SetBarrierTableName(tablename string)
SetBarrierTableName sets barrier table name
func TccGlobalTransaction ¶
func TccGlobalTransaction(dtm string, gid string, tccFunc TccGlobalFunc) (rerr error)
TccGlobalTransaction begin a tcc global transaction dtm dtm server address gid global transaction ID tccFunc define the detail tcc busi
func TccGlobalTransaction2 ¶
func TccGlobalTransaction2(dtm string, gid string, custom func(*Tcc), tccFunc TccGlobalFunc) (rerr error)
TccGlobalTransaction2 new version of TccGlobalTransaction, add custom param
func XaGlobalTransaction ¶
func XaGlobalTransaction(server string, gid string, xaFunc XaGlobalFunc) error
XaGlobalTransaction start a xa global transaction
func XaGlobalTransaction2 ¶
func XaGlobalTransaction2(server string, gid string, custom func(*Xa), xaFunc XaGlobalFunc) (rerr error)
XaGlobalTransaction2 start a xa global transaction with xa custom function
func XaLocalTransaction ¶
func XaLocalTransaction(qs url.Values, dbConf DBConf, xaFunc XaLocalFunc) error
XaLocalTransaction start a xa local transaction
Types ¶
type BarrierBusiFunc ¶
BarrierBusiFunc type for busi func
type BranchBarrier ¶
type BranchBarrier struct { TransType string Gid string BranchID string Op string BarrierID int DBType string // DBTypeMysql | DBTypePostgres BarrierTableName string }
BranchBarrier every branch info
func BarrierFrom ¶
func BarrierFrom(transType, gid, branchID, op string) (*BranchBarrier, error)
BarrierFrom construct transaction info from request
func BarrierFromQuery ¶
func BarrierFromQuery(qs url.Values) (*BranchBarrier, error)
BarrierFromQuery construct transaction info from request
func (*BranchBarrier) Call ¶
func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error)
Call see detail description in https://en.dtm.pub/practice/barrier.html tx: local transaction connection busiCall: busi func
func (*BranchBarrier) CallWithDB ¶
func (bb *BranchBarrier) CallWithDB(db *sql.DB, busiCall BarrierBusiFunc) error
CallWithDB the same as Call, but with *sql.DB
func (*BranchBarrier) MongoCall ¶
func (bb *BranchBarrier) MongoCall(mc *mongo.Client, busiCall func(mongo.SessionContext) error) (rerr error)
MongoCall sub-trans barrier for mongo. see http://dtm.pub/practice/barrier experimental
func (*BranchBarrier) MongoQueryPrepared ¶
func (bb *BranchBarrier) MongoQueryPrepared(mc *mongo.Client) error
MongoQueryPrepared query prepared for redis experimental
func (*BranchBarrier) QueryPrepared ¶
func (bb *BranchBarrier) QueryPrepared(db *sql.DB) error
QueryPrepared queries prepared data
func (*BranchBarrier) RedisCheckAdjustAmount ¶
func (bb *BranchBarrier) RedisCheckAdjustAmount(rd *redis.Client, key string, amount int, barrierExpire int) error
RedisCheckAdjustAmount check the value of key is valid and >= amount. then adjust the amount
func (*BranchBarrier) RedisQueryPrepared ¶
func (bb *BranchBarrier) RedisQueryPrepared(rd *redis.Client, barrierExpire int) error
RedisQueryPrepared query prepared for redis
func (*BranchBarrier) String ¶
func (bb *BranchBarrier) String() string
type Msg ¶
Msg reliable msg type
func (*Msg) BuildCustomOptions ¶
func (s *Msg) BuildCustomOptions()
BuildCustomOptions add custom options to the request context
func (*Msg) DoAndSubmit ¶
func (s *Msg) DoAndSubmit(queryPrepared string, busiCall func(bb *BranchBarrier) error) error
DoAndSubmit one method for the entire prepare->busi->submit the error returned by busiCall will be returned if busiCall return ErrFailure, then abort is called directly if busiCall return not nil error other than ErrFailure, then DoAndSubmit will call queryPrepared to get the result
func (*Msg) DoAndSubmitDB ¶
DoAndSubmitDB short method for Do on db type. please see DoAndSubmit
type Saga ¶
Saga struct of saga
func (*Saga) AddBranchOrder ¶
AddBranchOrder specify that branch should be after preBranches. branch should is larger than all the element in preBranches
func (*Saga) BuildCustomOptions ¶
func (s *Saga) BuildCustomOptions()
BuildCustomOptions add custom options to the request context
func (*Saga) SetConcurrent ¶
SetConcurrent enable the concurrent exec of sub trans
type TccGlobalFunc ¶
TccGlobalFunc type of global tcc call
type Xa ¶
Xa xa transaction
func XaFromQuery ¶
XaFromQuery construct xa info from request
func (*Xa) CallBranch ¶
CallBranch call a xa branch
type XaGlobalFunc ¶
XaGlobalFunc type of xa global function