diff --git a/dtmcli/dtmimp/consts.go b/dtmcli/dtmimp/consts.go index 95757ac..54586af 100644 --- a/dtmcli/dtmimp/consts.go +++ b/dtmcli/dtmimp/consts.go @@ -55,4 +55,9 @@ const ( // XaBarrier1 const for xa barrier id XaBarrier1 = "01" + + // ProtocolGRPC const for protocol grpc + ProtocolGRPC = "grpc" + // ProtocolHTTP const for protocol http + ProtocolHTTP = "http" ) diff --git a/dtmsvr/trans_class.go b/dtmsvr/trans_class.go index 5023e06..bedb590 100644 --- a/dtmsvr/trans_class.go +++ b/dtmsvr/trans_class.go @@ -31,7 +31,7 @@ func (t *TransGlobal) setupPayloads() { } } if t.Protocol == "" { - t.Protocol = "http" + t.Protocol = dtmimp.ProtocolHTTP } } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 2d78241..6184c2f 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -89,7 +89,7 @@ func (t *TransGlobal) getURLResult(uri string, branchID, op string, branchPayloa if uri == "" { // empty url is success return nil } - if t.Protocol == "http" || strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") { + if t.Protocol == dtmimp.ProtocolHTTP || strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") { if t.RequestTimeout != 0 { dtmimp.RestyClient.SetTimeout(time.Duration(t.RequestTimeout) * time.Second) } @@ -146,7 +146,7 @@ func (t *TransGlobal) getURLResult(uri string, branchID, op string, branchPayloa } return dtmimp.RespAsErrorCompatible(resp) } - dtmimp.PanicIf(t.Protocol == "http", fmt.Errorf("bad url for http: %s", uri)) + dtmimp.PanicIf(t.Protocol == dtmimp.ProtocolHTTP, fmt.Errorf("bad url for http: %s", uri)) // grpc handler server, method, err := dtmdriver.GetDriver().ParseServerMethod(uri) if err != nil {