Skip to content

Commit

Permalink
refactor: remove internal spec's annotations (#50)
Browse files Browse the repository at this point in the history
* feat: remove handling internal spec's annotations

* udpate kitex

* fix
  • Loading branch information
AsterDY committed May 8, 2024
1 parent 4e6336a commit cdf39e6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions conv/j2t/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -66,6 +67,7 @@ func TestMain(m *testing.M) {
}
}()
time.Sleep(time.Millisecond)
annotation.InitAGWAnnos()
m.Run()
}

Expand Down
2 changes: 2 additions & 0 deletions conv/t2j/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -61,6 +62,7 @@ func TestMain(m *testing.M) {
}
}()
time.Sleep(time.Millisecond)
annotation.InitAGWAnnos()
m.Run()
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ 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=
github.com/cloudwego/iasm v0.0.9/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
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=
Expand Down
2 changes: 2 additions & 0 deletions testdata/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -49,6 +50,7 @@ func TestMain(m *testing.M) {
}
}()
time.Sleep(time.Millisecond)
annotation.InitAGWAnnos()
m.Run()
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/idl/example3.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions thrift/annotation/anno_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions thrift/annotation/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cdf39e6

Please sign in to comment.