Skip to content

Commit be99ee9

Browse files
committed
finish trimmer-compose enabled by thriftgo
1 parent f2737ec commit be99ee9

File tree

27 files changed

+984
-295
lines changed

27 files changed

+984
-295
lines changed

generator/golang/backend.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func (g *GoBackend) Generate(req *plugin.Request, log backend.LogFunc) *plugin.R
8989
g.prepareUtilities()
9090
if g.utils.Features().TrimIDL {
9191
g.log.Warn("You Are Using IDL Trimmer")
92-
structureTrimmed, fieldTrimmed, err := trim.TrimAST(&trim.TrimASTArg{Ast: req.AST, TrimMethods: nil, Preserve: nil})
92+
structureTrimmed, fieldTrimmed, err := trim.TrimASTWithCompose(&trim.TrimASTWithComposeArg{
93+
TargetAST: req.AST,
94+
ReadCfgFromLocal: true,
95+
})
9396
if err != nil {
9497
g.log.Warn("trim error:", err.Error())
9598
}

tool/trimmer/compose_args.go

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2024 CloudWeGo Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
idls:
16+
test1.thrift:
17+
trimmer:
18+
methods:
19+
- "TestService.func1"
20+
- "TestService.func3"
21+
preserve: true
22+
preserved_structs:
23+
- "useless"
24+
match_go_name: true
25+
test2.thrift:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 CloudWeGo Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
methods:
16+
- "TestService.func1"
17+
- "TestService.func3"
18+
preserve: true
19+
preserved_structs:
20+
- "useless"
21+
match_go_name: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2024 CloudWeGo Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
idls:
16+
test1.thrift:
17+
trimmer:
18+
methods:
19+
- "TestService.func1"
20+
- "TestService.func3"
21+
preserve: true
22+
preserved_structs:
23+
- "useless"
24+
match_go_name: true
25+
test2.thrift:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 CloudWeGo Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
methods:
16+
- "TestService.func1"
17+
- "TestService.func3"
18+
preserve: true
19+
preserved_structs:
20+
- "useless"
21+
match_go_name: true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace go tests.multiple.common
16+
17+
enum Common1Enum1 {
18+
ONE
19+
TWO
20+
THREE
21+
}
22+
23+
enum Common1Enum2 {
24+
ONE
25+
TWO
26+
THERR
27+
}
28+
29+
struct Common1Struct1 {
30+
1: required string field
31+
}
32+
33+
struct Common1Struct2 {
34+
1: required string field
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace go tests.multiple.common
16+
17+
enum Common2Enum1 {
18+
ONE
19+
TWO
20+
THREE
21+
}
22+
23+
enum Common2Enum2 {
24+
ONE
25+
TWO
26+
THERR
27+
}
28+
29+
struct Common2Struct1 {
30+
1: required string field
31+
}
32+
33+
struct Common2Struct2 {
34+
1: required string field
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace go multiple.include.common
16+
17+
include "../common1.thrift"
18+
19+
struct Test1Struct1 {
20+
1: required common1.Common1Enum1 enumField
21+
2: required common1.Common1Struct1 structField
22+
}
23+
24+
service Test1 {
25+
string Process(1: Test1Struct1 req)
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace go multiple.include.common
16+
17+
include "../common1.thrift"
18+
19+
struct Test2Struct1 {
20+
1: required common1.Common1Enum2 enumField
21+
2: required common1.Common1Struct2 structField
22+
}
23+
24+
service Test2 {
25+
string Process(1: Test2Struct1 req)
26+
}

0 commit comments

Comments
 (0)