Skip to content

Commit ccf63c8

Browse files
author
Felix021
authored
fix: streaming support --combine-service (#50)
1 parent 3d87114 commit ccf63c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6257
-3
lines changed

thrift_streaming/combine_handler.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2023 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+
package thrift_streaming
16+
17+
import (
18+
"context"
19+
"io"
20+
21+
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/combine"
22+
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/combine/combineservice"
23+
)
24+
25+
var _ combineservice.CombineService = new(CombineServiceImpl)
26+
27+
type CombineServiceImpl struct{}
28+
29+
func (c CombineServiceImpl) Foo(ctx context.Context, req *combine.Req) (rsp *combine.Rsp, err error) {
30+
rsp = &combine.Rsp{Message: req.Message}
31+
return
32+
}
33+
34+
func (c CombineServiceImpl) Bar(stream combine.B_BarServer) (err error) {
35+
for {
36+
req, err := stream.Recv()
37+
if err == io.EOF {
38+
return nil
39+
}
40+
if err != nil {
41+
return err
42+
}
43+
44+
err = stream.Send(&combine.Rsp{Message: req.Message})
45+
if err != nil {
46+
return err
47+
}
48+
}
49+
}

thrift_streaming/generate.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ function generate_new() {
8080

8181
# Thrift
8282
kitex $module $idl
83+
kitex $module --combine-service idl/combine.thrift
8384

8485
# Thrift Slim
8586
kitex -thrift template=slim -gen-path kitex_gen_slim $module $idl
87+
kitex -thrift template=slim -gen-path kitex_gen_slim $module --combine-service idl/combine.thrift
8688

8789
# KitexPB
8890
kitex $module idl/api.proto

thrift_streaming/idl/api.thrift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ service EchoService {
3939
void EchoOneway(1: EchoRequest req1),
4040
void Ping(),
4141
}
42+
43+
// for checking whether the generated code is ok
44+
service PingPongOnlyService {
45+
EchoResponse EchoPingPong (1: EchoRequest req1),
46+
}
47+
48+
// for checking whether the generated code is ok
49+
service StreamOnlyService {
50+
EchoResponse EchoBidirectional (1: EchoRequest req1) (streaming.mode="bidirectional"),
51+
}

thrift_streaming/idl/combine.thrift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2023 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 combine
16+
17+
struct Req {
18+
1: required string message,
19+
}
20+
21+
struct Rsp {
22+
1: required string message,
23+
}
24+
25+
service A {
26+
Rsp Foo(1: Req req),
27+
}
28+
29+
service B {
30+
Rsp Bar(1: Req req) (streaming.mode="bidirectional"),
31+
}

0 commit comments

Comments
 (0)