diff --git a/go.mod b/go.mod index ba693ecf..9e2c0da5 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/apache/dubbo-go-hessian2 v1.12.4 + github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b github.com/cloudwego/kitex v0.8.0 github.com/cloudwego/thriftgo v0.3.3 github.com/stretchr/testify v1.8.2 diff --git a/go_format.sh b/go_format.sh old mode 100644 new mode 100755 diff --git a/pkg/codec.go b/pkg/codec.go index b89463c7..a0056552 100644 --- a/pkg/codec.go +++ b/pkg/codec.go @@ -25,13 +25,13 @@ import ( hessian2_exception "github.com/kitex-contrib/codec-dubbo/pkg/hessian2/exception" - "github.com/kitex-contrib/codec-dubbo/registries" - + "github.com/bytedance/gopkg/cloud/metainfo" "github.com/cloudwego/kitex/pkg/remote" "github.com/cloudwego/kitex/pkg/remote/codec" "github.com/kitex-contrib/codec-dubbo/pkg/dubbo_spec" "github.com/kitex-contrib/codec-dubbo/pkg/hessian2" "github.com/kitex-contrib/codec-dubbo/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/registries" ) var _ remote.Codec = (*DubboCodec)(nil) @@ -453,22 +453,17 @@ func processAttachments(decoder iface.Decoder, message remote.Message) error { if attachments, ok := attachmentsRaw.(map[interface{}]interface{}); ok { transStrMap := map[string]string{} - transIntMap := map[uint16]string{} for keyRaw, val := range attachments { if key, ok := keyRaw.(string); ok { message.Tags()[key] = val if v, ok := val.(string); ok { - transStrMap[key] = v - } - } - if uint16Key, ok := keyRaw.(uint16); ok { - if v, ok := val.(string); ok { - transIntMap[uint16Key] = v + // The prefix needs to be added + transStrMap[metainfo.PrefixTransient+key] = v } } } + message.TransInfo().PutTransStrInfo(transStrMap) - message.TransInfo().PutTransIntInfo(transIntMap) return nil } diff --git a/pkg/dubbo_spec/attachment.go b/pkg/dubbo_spec/attachment.go index 45b3d4e3..682595e3 100644 --- a/pkg/dubbo_spec/attachment.go +++ b/pkg/dubbo_spec/attachment.go @@ -21,8 +21,10 @@ package dubbo_spec import ( "strconv" + "strings" "time" + "github.com/bytedance/gopkg/cloud/metainfo" "github.com/cloudwego/kitex/pkg/remote" ) @@ -32,9 +34,11 @@ const ( INTERFACE_KEY = "interface" VERSION_KEY = "version" TIMEOUT_KEY = "timeout" + + lenPT = len(metainfo.PrefixTransient) ) -type Attachment = map[interface{}]interface{} +type Attachment = map[string]interface{} func NewAttachment(path, group, iface, version string, timeout time.Duration, transInfo remote.TransInfo) Attachment { result := Attachment{} @@ -53,11 +57,13 @@ func NewAttachment(path, group, iface, version string, timeout time.Duration, tr if timeout > 0 { result[TIMEOUT_KEY] = strconv.Itoa(int(timeout.Milliseconds())) } - for k, v := range transInfo.TransIntInfo() { - result[k] = v - } for k, v := range transInfo.TransStrInfo() { - result[k] = v + // The prefix needs to be removed + if strings.HasPrefix(k, metainfo.PrefixTransient) { + result[k[lenPT:]] = v + } else { + result[k] = v + } } return result }