Skip to content

Commit

Permalink
fix: streaming support --combine-service (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix021 authored Jan 16, 2024
1 parent 3d87114 commit ccf63c8
Show file tree
Hide file tree
Showing 55 changed files with 6,257 additions and 3 deletions.
49 changes: 49 additions & 0 deletions thrift_streaming/combine_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 thrift_streaming

import (
"context"
"io"

"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/combine"
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/combine/combineservice"
)

var _ combineservice.CombineService = new(CombineServiceImpl)

type CombineServiceImpl struct{}

func (c CombineServiceImpl) Foo(ctx context.Context, req *combine.Req) (rsp *combine.Rsp, err error) {
rsp = &combine.Rsp{Message: req.Message}
return
}

func (c CombineServiceImpl) Bar(stream combine.B_BarServer) (err error) {
for {
req, err := stream.Recv()
if err == io.EOF {
return nil
}
if err != nil {
return err
}

err = stream.Send(&combine.Rsp{Message: req.Message})
if err != nil {
return err
}
}
}
2 changes: 2 additions & 0 deletions thrift_streaming/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ function generate_new() {

# Thrift
kitex $module $idl
kitex $module --combine-service idl/combine.thrift

# Thrift Slim
kitex -thrift template=slim -gen-path kitex_gen_slim $module $idl
kitex -thrift template=slim -gen-path kitex_gen_slim $module --combine-service idl/combine.thrift

# KitexPB
kitex $module idl/api.proto
Expand Down
10 changes: 10 additions & 0 deletions thrift_streaming/idl/api.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ service EchoService {
void EchoOneway(1: EchoRequest req1),
void Ping(),
}

// for checking whether the generated code is ok
service PingPongOnlyService {
EchoResponse EchoPingPong (1: EchoRequest req1),
}

// for checking whether the generated code is ok
service StreamOnlyService {
EchoResponse EchoBidirectional (1: EchoRequest req1) (streaming.mode="bidirectional"),
}
31 changes: 31 additions & 0 deletions thrift_streaming/idl/combine.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.

namespace go combine

struct Req {
1: required string message,
}

struct Rsp {
1: required string message,
}

service A {
Rsp Foo(1: Req req),
}

service B {
Rsp Bar(1: Req req) (streaming.mode="bidirectional"),
}
Loading

0 comments on commit ccf63c8

Please sign in to comment.