diff --git a/conv/j2t/conv_test.go b/conv/j2t/conv_test.go index 35d0f178..a4026285 100644 --- a/conv/j2t/conv_test.go +++ b/conv/j2t/conv_test.go @@ -46,6 +46,7 @@ import ( "github.com/cloudwego/dynamicgo/testdata/kitex_gen/null" "github.com/cloudwego/dynamicgo/testdata/sample" "github.com/cloudwego/dynamicgo/thrift" + "github.com/cloudwego/dynamicgo/thrift/annotation" "github.com/cloudwego/dynamicgo/thrift/base" "github.com/stretchr/testify/require" ) @@ -66,6 +67,7 @@ func TestMain(m *testing.M) { } }() time.Sleep(time.Millisecond) + annotation.InitAGWAnnos() m.Run() } diff --git a/conv/t2j/conv_test.go b/conv/t2j/conv_test.go index b56af8c9..026cf753 100644 --- a/conv/t2j/conv_test.go +++ b/conv/t2j/conv_test.go @@ -39,6 +39,7 @@ import ( kbase "github.com/cloudwego/dynamicgo/testdata/kitex_gen/base" "github.com/cloudwego/dynamicgo/testdata/kitex_gen/example3" "github.com/cloudwego/dynamicgo/thrift" + "github.com/cloudwego/dynamicgo/thrift/annotation" "github.com/cloudwego/dynamicgo/thrift/base" "github.com/davecgh/go-spew/spew" "github.com/stretchr/testify/assert" @@ -61,6 +62,7 @@ func TestMain(m *testing.M) { } }() time.Sleep(time.Millisecond) + annotation.InitAGWAnnos() m.Run() } diff --git a/go.mod b/go.mod index abe77aae..197dc84b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/bytedance/sonic/loader v0.1.1 github.com/cloudwego/base64x v0.1.4 github.com/cloudwego/fastpb v0.0.4 - github.com/cloudwego/kitex v0.9.3-rc + github.com/cloudwego/kitex v0.9.3-rc2 github.com/cloudwego/thriftgo v0.3.6 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/fatih/structtag v1.2.0 diff --git a/go.sum b/go.sum index dddaebd7..e9004d87 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,10 @@ github.com/cloudwego/base64x v0.1.3/go.mod h1:1+1K5BUHIQzyapgpF7LwvOGAEDicKtt1um github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/configmanager v0.2.1/go.mod h1:0oD/BWaTuznBOawVeTmTl3LE99RWaw7rX2jECowmY58= +github.com/cloudwego/configmanager v0.2.2/go.mod h1:ppiyU+5TPLonE8qMVi/pFQk2eL3Q4P7d4hbiNJn6jwI= github.com/cloudwego/dynamicgo v0.2.2-dep3/go.mod h1:oFLzd9SEUtU7XbSc7AT9e5xoAV1OJ1mVpudtUOiD7PQ= github.com/cloudwego/dynamicgo v0.2.2/go.mod h1:k840iCFH9ng9PBqr6jIoOyZxdk58EPEccrbfOk4ni1s= +github.com/cloudwego/dynamicgo v0.2.4/go.mod h1:BXXaLtNH/nNIZi5HsE8lupiMKPmTogJ8z+KGFEySqUg= github.com/cloudwego/fastpb v0.0.4 h1:/ROVVfoFtpfc+1pkQLzGs+azjxUbSOsAqSY4tAAx4mg= github.com/cloudwego/fastpb v0.0.4/go.mod h1:/V13XFTq2TUkxj2qWReV8MwfPC4NnPcy6FsrojnsSG0= github.com/cloudwego/frugal v0.1.15/go.mod h1:26kU1r18vA8vRg12c66XPDlfv1GQHDbE1RpusipXfcI= @@ -42,8 +44,9 @@ github.com/cloudwego/iasm v0.0.9/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cloudwego/kitex v0.9.3-dep3/go.mod h1:87pfgsZMaso0tFISQZzMhwmh6pajfVmw/R3COsh2pCg= -github.com/cloudwego/kitex v0.9.3-rc h1:1fiI74BMKuNEAVnnXbUr13Dom9XYp44/scRD3EkbOqs= github.com/cloudwego/kitex v0.9.3-rc/go.mod h1:QurmwA8Wh/s7qz6C+Da9sc9B4TRW6q4TN6Y56mu90SE= +github.com/cloudwego/kitex v0.9.3-rc2 h1:+B1j56Mo92McGNVSxwzZ2CrF7kbPnb9lfbWlTLrFems= +github.com/cloudwego/kitex v0.9.3-rc2/go.mod h1:0EAW3Mm5mmC483T+nqoBrDT96vgWRxtLpjeF8twLsc4= github.com/cloudwego/localsession v0.0.2/go.mod h1:kiJxmvAcy4PLgKtEnPS5AXed3xCiXcs7Z+KBHP72Wv8= github.com/cloudwego/netpoll v0.6.0 h1:JRMkrA1o8k/4quxzg6Q1XM+zIhwZsyoWlq6ef+ht31U= github.com/cloudwego/netpoll v0.6.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ= diff --git a/testdata/example_test.go b/testdata/example_test.go index 40839e79..c22500da 100644 --- a/testdata/example_test.go +++ b/testdata/example_test.go @@ -28,6 +28,7 @@ import ( "github.com/cloudwego/dynamicgo/testdata/kitex_gen/base" "github.com/cloudwego/dynamicgo/testdata/kitex_gen/example2" "github.com/cloudwego/dynamicgo/testdata/sample" + "github.com/cloudwego/dynamicgo/thrift/annotation" jsoniter "github.com/json-iterator/go" "github.com/stretchr/testify/require" ) @@ -49,6 +50,7 @@ func TestMain(m *testing.M) { } }() time.Sleep(time.Millisecond) + annotation.InitAGWAnnos() m.Run() } diff --git a/testdata/idl/example3.thrift b/testdata/idl/example3.thrift index cdc6d377..561f46ba 100644 --- a/testdata/idl/example3.thrift +++ b/testdata/idl/example3.thrift @@ -79,7 +79,7 @@ struct ExampleErrorResp { } struct ExampleInt2Float { - 1: i32 Int32 (agw.js_conv = ""), + 1: i32 Int32 (api.js_conv = ""), 2: double Float64 (api.js_conv = ""), 3: string String (go.tag="json:\"中文\"", api.js_conv = "") 4: i64 Int64 diff --git a/thrift/annotation/anno_mapping_test.go b/thrift/annotation/anno_mapping_test.go index 09e6b252..b67b2ded 100644 --- a/thrift/annotation/anno_mapping_test.go +++ b/thrift/annotation/anno_mapping_test.go @@ -24,6 +24,11 @@ import ( "github.com/stretchr/testify/require" ) +func TestMain(m *testing.M) { + InitAGWAnnos() + m.Run() +} + func TestGoTagJSON(t *testing.T) { p, err := GetDescFromContent(` namespace go kitex.test.server diff --git a/thrift/annotation/register.go b/thrift/annotation/register.go index 7cc5f3d6..f9d97356 100644 --- a/thrift/annotation/register.go +++ b/thrift/annotation/register.go @@ -39,26 +39,32 @@ func init() { // OptionMaker // ValueMapping - thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, JSConv)), "api.js_conv", "agw.js_conv") - thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, BodyDynamic)), "agw.body_dynamic") + thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, JSConv)), "api.js_conv") // KeyMapping - thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, APIKey)), "agw.key", APIKeyName) - // thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, NameCase)), "agw.to_snake", "janus.to_snake", "agw.to_lower_camel_case", "janus.to_lower_camel_case") - + // AnnotationMapper thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, goTagMapper{}, "go.tag") thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, apiBodyMapper{}, "api.body") // make raw.body not failed, expected caller to implement this anno thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, apiBodyMapper{}, "raw.body") - thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, sourceMapper{}, "janus.source", "agw.source") - thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, targetMapper{}, "agw.target", "janus.target") thrift.RegisterAnnotationMapper(thrift.AnnoScopeService, nameCaseMapper{}, NameCaseKeys...) thrift.RegisterAnnotationMapper(thrift.AnnoScopeFunction, nameCaseMapper{}, NameCaseKeys...) thrift.RegisterAnnotationMapper(thrift.AnnoScopeStruct, nameCaseMapper{}, NameCaseKeys...) thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, nameCaseMapper{}, NameCaseKeys...) } +// This is only used for internal specifications. +// DO NOT USE IT if you don't know related annotations +func InitAGWAnnos() { + thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, JSConv)), "agw.js_conv") + thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, BodyDynamic)), "agw.body_dynamic") + thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, APIKey)), "agw.key", APIKeyName) + // thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, NameCase)), "agw.to_snake", "janus.to_snake", "agw.to_lower_camel_case", "janus.to_lower_camel_case") + thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, sourceMapper{}, "janus.source", "agw.source") + thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, targetMapper{}, "agw.target", "janus.target") +} + //go:noline func errNotFound(key string, scope string) error { return meta.NewError(meta.ErrNotFound, fmt.Sprintf("not fould %s in %s", key, scope), nil)