Skip to content

Commit

Permalink
finish trimmer-compose enabled by thriftgo
Browse files Browse the repository at this point in the history
  • Loading branch information
DMwangnima committed May 30, 2024
1 parent 908ccc0 commit d32ea72
Show file tree
Hide file tree
Showing 27 changed files with 984 additions and 295 deletions.
5 changes: 4 additions & 1 deletion generator/golang/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (g *GoBackend) Generate(req *plugin.Request, log backend.LogFunc) *plugin.R
g.prepareUtilities()
if g.utils.Features().TrimIDL {
g.log.Warn("You Are Using IDL Trimmer")
structureTrimmed, fieldTrimmed, err := trim.TrimAST(&trim.TrimASTArg{Ast: req.AST, TrimMethods: nil, Preserve: nil})
structureTrimmed, fieldTrimmed, err := trim.TrimASTWithCompose(&trim.TrimASTWithComposeArg{
TargetAST: req.AST,
ReadCfgFromLocal: true,
})
if err != nil {
g.log.Warn("trim error:", err.Error())
}
Expand Down
148 changes: 0 additions & 148 deletions tool/trimmer/compose_args.go

This file was deleted.

25 changes: 25 additions & 0 deletions tool/trimmer/test_cases/config/idl_compose/idl_compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 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.

idls:
test1.thrift:
trimmer:
methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
test2.thrift:
21 changes: 21 additions & 0 deletions tool/trimmer/test_cases/config/trim_config/trim_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 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.

methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 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.

idls:
test1.thrift:
trimmer:
methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
test2.thrift:
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 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.

methods:
- "TestService.func1"
- "TestService.func3"
preserve: true
preserved_structs:
- "useless"
match_go_name: true
35 changes: 35 additions & 0 deletions tool/trimmer/test_cases/multiple_idls/common1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 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.

namespace go tests.multiple.common

enum Common1Enum1 {
ONE
TWO
THREE
}

enum Common1Enum2 {
ONE
TWO
THERR
}

struct Common1Struct1 {
1: required string field
}

struct Common1Struct2 {
1: required string field
}
35 changes: 35 additions & 0 deletions tool/trimmer/test_cases/multiple_idls/common2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 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.

namespace go tests.multiple.common

enum Common2Enum1 {
ONE
TWO
THREE
}

enum Common2Enum2 {
ONE
TWO
THERR
}

struct Common2Struct1 {
1: required string field
}

struct Common2Struct2 {
1: required string field
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 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.

namespace go multiple.include.common

include "../common1.thrift"

struct Test1Struct1 {
1: required common1.Common1Enum1 enumField
2: required common1.Common1Struct1 structField
}

service Test1 {
string Process(1: Test1Struct1 req)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 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.

namespace go multiple.include.common

include "../common1.thrift"

struct Test2Struct1 {
1: required common1.Common1Enum2 enumField
2: required common1.Common1Struct2 structField
}

service Test2 {
string Process(1: Test2Struct1 req)
}
Loading

0 comments on commit d32ea72

Please sign in to comment.