diff --git a/generator/golang/option.go b/generator/golang/option.go index 5a8eca6e..e894f571 100644 --- a/generator/golang/option.go +++ b/generator/golang/option.go @@ -48,7 +48,6 @@ type Features struct { AlwaysGenerateJSONTag bool `always_gen_json_tag:"Always generate 'json' tag even if go.tag is provided (Disabled by default)"` SnakeTyleJSONTag bool `snake_style_json_tag:"Generate snake style json tag"` LowerCamelCaseJSONTag bool `lower_camel_style_json_tag:"Generate lower camel case style json tag"` - GenerateReflectionInfo bool `generate_reflection_info:"This option is no longer used. Please use with_reflection instead."` WithReflection bool `with_reflection:"Generate reflection info"` EnumAsINT32 bool `enum_as_int_32:"Generate enum type as int32"` CodeRefSlim bool `code_ref_slim:"Generate code ref by given idl-ref.yaml with less refs to avoid conflict"` @@ -98,7 +97,6 @@ var defaultFeatures = Features{ AlwaysGenerateJSONTag: false, SnakeTyleJSONTag: false, LowerCamelCaseJSONTag: false, - GenerateReflectionInfo: false, ThriftStreaming: false, EnumAsINT32: false, TrimIDL: false, diff --git a/generator/golang/scope.go b/generator/golang/scope.go index 5a9093ca..f5d8fcd0 100644 --- a/generator/golang/scope.go +++ b/generator/golang/scope.go @@ -22,7 +22,6 @@ import ( "github.com/cloudwego/thriftgo/generator/golang/streaming" "github.com/cloudwego/thriftgo/parser" "github.com/cloudwego/thriftgo/pkg/namespace" - "github.com/cloudwego/thriftgo/reflection" "github.com/cloudwego/thriftgo/thrift_reflection" ) @@ -145,10 +144,6 @@ func (s *Scope) FilePackage() string { return s.importPackage } -func (s *Scope) IDLMeta() string { - return reflection.Encode(s.ast) -} - func (s *Scope) IDLName() string { idlName := strings.TrimSuffix(s.ast.Filename, ".thrift") arr := strings.Split(idlName, string(filepath.Separator)) diff --git a/generator/golang/templates/file.go b/generator/golang/templates/file.go index dbe71266..058b6f36 100644 --- a/generator/golang/templates/file.go +++ b/generator/golang/templates/file.go @@ -22,7 +22,6 @@ package {{.FilePackage}} import ( {{InsertionPoint "imports"}} - {{- if Features.GenerateReflectionInfo}}thriftreflection "github.com/cloudwego/kitex/pkg/reflection/thrift"{{end}} ) {{template "Constant" .}} @@ -68,11 +67,5 @@ var ( {{- end}} {{- end}} -{{- if Features.GenerateReflectionInfo}} - var file_{{.IDLName}}_rawDesc = {{.IDLMeta}} - func init(){ - thriftreflection.RegisterIDL(file_{{.IDLName}}_rawDesc) - } -{{end}} {{- InsertionPoint "eof"}} ` diff --git a/generator/golang/templates/raw_struct/raw_struct.go b/generator/golang/templates/raw_struct/raw_struct.go index 31eadda2..80b733bd 100644 --- a/generator/golang/templates/raw_struct/raw_struct.go +++ b/generator/golang/templates/raw_struct/raw_struct.go @@ -58,7 +58,6 @@ package {{.FilePackage}} import ( {{InsertionPoint "imports"}} - {{- if Features.GenerateReflectionInfo}}thriftreflection "github.com/cloudwego/kitex/pkg/reflection/thrift"{{end}} ) {{template "Constant" .}} diff --git a/reflection/FileDescriptor.go b/reflection/FileDescriptor.go deleted file mode 100644 index 4082fcc6..00000000 --- a/reflection/FileDescriptor.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2023 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package reflection - -import ( - "bytes" - "compress/gzip" - "encoding/json" - "fmt" - "io/ioutil" - "strings" - - "github.com/cloudwego/thriftgo/parser" -) - -type FileDescriptor struct { - Filename string `thrift:"Filename,1" json:"Filename"` - IncludeMap map[string]string `thrift:"IncludeMap,2" json:"Include"` - Typedefs []*parser.Typedef `thrift:"Typedefs,5" json:"Typedefs"` - Constants []*parser.Constant `thrift:"Constants,6" json:"Constants"` - Enums []*parser.Enum `thrift:"Enums,7" json:"Enums"` - Structs []*parser.StructLike `thrift:"Structs,8" json:"Structs"` - Unions []*parser.StructLike `thrift:"Unions,9" json:"Unions"` - Exceptions []*parser.StructLike `thrift:"Exceptions,10" json:"Exceptions"` - Services []*parser.Service `thrift:"Services,11" json:"Services"` -} - -func JsonEncode(f *FileDescriptor) ([]byte, error) { - data, err := json.MarshalIndent(f, "", " ") - if err != nil { - return nil, err - } - return data, nil -} - -func JsonDecode(data []byte) (*FileDescriptor, error) { - f := &FileDescriptor{} - err := json.Unmarshal(data, f) - if err != nil { - return nil, err - } - return f, nil -} - -func Encode(p *parser.Thrift) string { - // alias prefix -> path - includeMap := map[string]string{} - for _, inc := range p.Includes { - arr := strings.Split(strings.TrimSuffix(inc.Path, ".thrift"), "/") - alias := arr[len(arr)-1] - includeMap[alias] = inc.Path - } - f := &FileDescriptor{ - Filename: p.Filename, - IncludeMap: includeMap, - Typedefs: p.Typedefs, - Constants: p.Constants, - Enums: p.Enums, - Structs: p.Structs, - Unions: p.Unions, - Exceptions: p.Exceptions, - Services: p.Services, - } - bytes, _ := JsonEncode(f) - bytes, _ = doGzip(bytes) - byteStr := fmt.Sprintf("% x", bytes) - byteStr = strings.ReplaceAll(byteStr, " ", ",0x") - byteStr = "[]byte" + "{\n0x" + byteStr + "}" - return byteStr -} - -func Decode(data []byte) *FileDescriptor { - data, _ = unGzip(data) - f, _ := JsonDecode(data) - return f -} - -func doGzip(data []byte) ([]byte, error) { - var buffer bytes.Buffer - writer := gzip.NewWriter(&buffer) - _, err := writer.Write(data) - if err != nil { - return nil, err - } - writer.Close() - compressedData, err := ioutil.ReadAll(&buffer) - return compressedData, nil -} - -func unGzip(data []byte) ([]byte, error) { - var buffer bytes.Buffer - buffer.Write(data) - reader, _ := gzip.NewReader(&buffer) - defer reader.Close() - undatas, _ := ioutil.ReadAll(reader) - return undatas, nil -}