mirror of https://github.com/dtm-labs/dtm.git
csharpjavadistributed-transactionsdtmgogolangmicroservicenodejsphpdatabasesagaseatatcctransactiontransactionsxapythondistributed
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
/*
|
|
* Copyright (c) 2021 yedf. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style
|
|
* license that can be found in the LICENSE file.
|
|
*/
|
|
|
|
package dtmimp
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/dtm-labs/dtm/dtmcli/logger"
|
|
"github.com/dtm-labs/dtmdriver"
|
|
"github.com/go-resty/resty/v2"
|
|
)
|
|
|
|
// ErrFailure error of FAILURE
|
|
var ErrFailure = errors.New("FAILURE")
|
|
|
|
// ErrOngoing error of ONGOING
|
|
var ErrOngoing = errors.New("ONGOING")
|
|
|
|
// ErrDuplicated error of DUPLICATED for only msg
|
|
// if QueryPrepared executed before call. then DoAndSubmit return this error
|
|
var ErrDuplicated = errors.New("DUPLICATED")
|
|
|
|
// XaSQLTimeoutMs milliseconds for Xa sql to timeout
|
|
var XaSQLTimeoutMs = 15000
|
|
|
|
// MapSuccess HTTP result of SUCCESS
|
|
var MapSuccess = map[string]interface{}{"dtm_result": ResultSuccess}
|
|
|
|
// MapFailure HTTP result of FAILURE
|
|
var MapFailure = map[string]interface{}{"dtm_result": ResultFailure}
|
|
|
|
// RestyClient the resty object
|
|
var RestyClient = resty.New()
|
|
|
|
// PassthroughHeaders will be passed to every sub-trans call
|
|
var PassthroughHeaders = []string{}
|
|
|
|
// BarrierTableName the table name of barrier table
|
|
var BarrierTableName = "dtm_barrier.barrier"
|
|
|
|
// BeforeRequest is the middleware for default resty.Client
|
|
func BeforeRequest(c *resty.Client, r *resty.Request) error {
|
|
r.URL = MayReplaceLocalhost(r.URL)
|
|
u, err := dtmdriver.GetHTTPDriver().ResolveURL(r.URL)
|
|
logger.Debugf("requesting: %s %s %s resolved: %s", r.Method, r.URL, MustMarshalString(r.Body), u)
|
|
r.URL = u
|
|
return err
|
|
}
|
|
|
|
// AfterResponse is the middleware for default resty.Client
|
|
func AfterResponse(c *resty.Client, resp *resty.Response) error {
|
|
r := resp.Request
|
|
logger.Debugf("requested: %d %s %s %s", resp.StatusCode(), r.Method, r.URL, resp.String())
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
RestyClient.OnBeforeRequest(BeforeRequest)
|
|
RestyClient.OnAfterResponse(AfterResponse)
|
|
}
|
|
|