Documentation
¶
Index ¶
- Constants
- Variables
- func AsError(x interface{}) error
- func CatchP(f func()) (rerr error)
- func CheckResponse(resp *resty.Response, err error) error
- func CheckResult(res interface{}, err error) error
- func DBExec(db DB, sql string, values ...interface{}) (affected int64, rerr error)
- func E2P(err error)
- func GetCurrentDBType() string
- func GetDsn(conf DBConf) string
- func GetFuncName() string
- func If(condition bool, trueObj interface{}, falseObj interface{}) interface{}
- func MayReplaceLocalhost(host string) string
- func MustAtoi(s string) int
- func MustMarshal(v interface{}) []byte
- func MustMarshalString(v interface{}) string
- func MustRemarshal(from interface{}, to interface{})
- func MustUnmarshal(b []byte, obj interface{})
- func MustUnmarshalString(s string, obj interface{})
- func OrString(ss ...string) string
- func P2E(perr *error)
- func PanicIf(cond bool, err error)
- func PooledDB(conf DBConf) (*sql.DB, error)
- func SetCurrentDBType(dbType string)
- func StandaloneDB(conf DBConf) (*sql.DB, error)
- func TransCallDtm(tb *TransBase, body interface{}, operation string) error
- func TransRegisterBranch(tb *TransBase, added map[string]string, operation string) error
- func TransRequestBranch(t *TransBase, body interface{}, branchID string, op string, url string) (*resty.Response, error)
- type BranchIDGen
- type DB
- type DBConf
- type DBSpecial
- type TransBase
- type TransOptions
- type XaClientBase
- func (xc *XaClientBase) HandleCallback(gid string, branchID string, action string) error
- func (xc *XaClientBase) HandleGlobalTrans(xa *TransBase, callDtm func(string) error, callBusi func() error) (rerr error)
- func (xc *XaClientBase) HandleLocalTrans(xa *TransBase, cb func(*sql.DB) error) (rerr error)
Constants ¶
const ( // ResultFailure for result of a trans/trans branch ResultFailure = "FAILURE" // ResultSuccess for result of a trans/trans branch ResultSuccess = "SUCCESS" // ResultOngoing for result of a trans/trans branch ResultOngoing = "ONGOING" // DBTypeMysql const for driver mysql DBTypeMysql = "mysql" // DBTypePostgres const for driver postgres DBTypePostgres = "postgres" // DBTypeRedis const for driver redis DBTypeRedis = "redis" )
Variables ¶
var BarrierTableName = "dtm_barrier.barrier"
BarrierTableName the table name of barrier table
var ErrFailure = errors.New("FAILURE")
ErrFailure error of FAILURE
var ErrOngoing = errors.New("ONGOING")
ErrOngoing error of ONGOING
var FatalIfError = logger.FatalIfError
FatalIfError fatal if error is not nil Deprecated: use logger.FatalIfError
var LogIfFatalf = logger.FatalfIf
LogIfFatalf fatal if cond is true Deprecated: use logger.FatalfIf
var LogRedf = logger.Errorf
LogRedf an alias of Errorf Deprecated: use logger.Errorf
var Logf = logger.Infof
Logf an alias of Infof Deprecated: use logger.Errorf
var MapFailure = map[string]interface{}{"dtm_result": ResultFailure}
MapFailure HTTP result of FAILURE
var MapSuccess = map[string]interface{}{"dtm_result": ResultSuccess}
MapSuccess HTTP result of SUCCESS
var PassthroughHeaders = []string{}
PassthroughHeaders will be passed to every sub-trans call
var RestyClient = resty.New()
RestyClient the resty object
var XaSqlTimeoutMs = 15000
XaSqlTimeoutMs milliseconds for Xa sql to timeout
Functions ¶
func CheckResponse ¶
CheckResponse is check response, and return corresponding error by the condition of resp when err is nil. Otherwise, return err directly.
func CheckResult ¶
CheckResult is check result. Return err directly if err is not nil. And return corresponding error by calling CheckResponse if resp is the type of *resty.Response. Otherwise, return error by value of str, the string after marshal.
func If ¶
func If(condition bool, trueObj interface{}, falseObj interface{}) interface{}
If ternary operator
func MayReplaceLocalhost ¶
MayReplaceLocalhost when run in docker compose, change localhost to host.docker.internal for accessing host network
func MustMarshalString ¶
func MustMarshalString(v interface{}) string
MustMarshalString string version of MustMarshal
func MustRemarshal ¶
func MustRemarshal(from interface{}, to interface{})
MustRemarshal marshal and unmarshal, and check error
func MustUnmarshal ¶
func MustUnmarshal(b []byte, obj interface{})
MustUnmarshal checked version for unmarshal
func MustUnmarshalString ¶
func MustUnmarshalString(s string, obj interface{})
MustUnmarshalString string version of MustUnmarshal
func StandaloneDB ¶
StandaloneDB get a standalone db instance
func TransCallDtm ¶
TransCallDtm TransBase call dtm
func TransRegisterBranch ¶
TransRegisterBranch TransBase register a branch to dtm
Types ¶
type BranchIDGen ¶
type BranchIDGen struct { BranchID string // contains filtered or unexported fields }
BranchIDGen used to generate a sub branch id
func (*BranchIDGen) CurrentSubBranchID ¶
func (g *BranchIDGen) CurrentSubBranchID() string
CurrentSubBranchID return current branchID
func (*BranchIDGen) NewSubBranchID ¶
func (g *BranchIDGen) NewSubBranchID() string
NewSubBranchID generate a sub branch id
type DB ¶
type DB interface { Exec(query string, args ...interface{}) (sql.Result, error) QueryRow(query string, args ...interface{}) *sql.Row }
DB inteface of dtmcli db
type DBSpecial ¶
type DBSpecial interface { GetPlaceHoldSQL(sql string) string GetInsertIgnoreTemplate(tableAndValues string, pgConstraint string) string GetXaSQL(command string, xid string) string }
DBSpecial db specific operations
type TransBase ¶
type TransBase struct { Gid string `json:"gid"` TransType string `json:"trans_type"` Dtm string `json:"-"` CustomData string `json:"custom_data,omitempty"` TransOptions Steps []map[string]string `json:"steps,omitempty"` // use in MSG/SAGA Payloads []string `json:"payloads,omitempty"` // used in MSG/SAGA BinPayloads [][]byte `json:"-"` BranchIDGen `json:"-"` // used in XA/TCC Op string `json:"-"` // used in XA/TCC QueryPrepared string `json:"query_prepared,omitempty"` // used in MSG }
TransBase base for all trans
func NewTransBase ¶
NewTransBase new a TransBase
func TransBaseFromQuery ¶
TransBaseFromQuery construct transaction info from request
type TransOptions ¶
type TransOptions struct { WaitResult bool `json:"wait_result,omitempty" gorm:"-"` TimeoutToFail int64 `json:"timeout_to_fail,omitempty" gorm:"-"` // for trans type: xa, tcc RetryInterval int64 `json:"retry_interval,omitempty" gorm:"-"` // for trans type: msg saga xa tcc PassthroughHeaders []string `json:"passthrough_headers,omitempty" gorm:"-"` BranchHeaders map[string]string `json:"branch_headers,omitempty" gorm:"-"` }
TransOptions transaction options
type XaClientBase ¶
XaClientBase XaClient/XaGrpcClient base. shared by http and grpc
func (*XaClientBase) HandleCallback ¶
func (xc *XaClientBase) HandleCallback(gid string, branchID string, action string) error
HandleCallback type of commit/rollback callback handler
func (*XaClientBase) HandleGlobalTrans ¶
func (xc *XaClientBase) HandleGlobalTrans(xa *TransBase, callDtm func(string) error, callBusi func() error) (rerr error)
HandleGlobalTrans http/grpc GlobalTransaction的公共方法
func (*XaClientBase) HandleLocalTrans ¶
HandleLocalTrans public handler of LocalTransaction via http/grpc