generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felix021
authored
Jan 11, 2024
1 parent
191f8cf
commit d09f7be
Showing
63 changed files
with
21,720 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ grpc_gen/ | |
go.mod | ||
go.sum | ||
bin | ||
thrift_streaming/binaries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
|
||
|
||
# Regenerate kitex_gen* directories when there's any related change to codegen (both kitex&thriftgo) | ||
|
||
cd `dirname $0` | ||
ROOT=`pwd` | ||
|
||
set -e | ||
|
||
# Old binaries: kitex <= v0.8.0 && thriftgo <= v0.3.4 | ||
OLD=$ROOT/binaries/github-old | ||
|
||
# New binaries: kitex >= v0.8.1 && thriftgo >= v0.3.5 | ||
NEW=$ROOT/binaries/github-new | ||
|
||
# kitex >= v0.8.1 && thriftgo <= v0.3.4 | ||
NEW_THRIFTGO_OLD_KITEX=$ROOT/binaries/github-new-thriftgo-old-kitex | ||
|
||
module='-module github.com/cloudwego/kitex-tests' | ||
idl=idl/api.thrift | ||
|
||
SAVE_PATH=$PATH | ||
|
||
# generate with old kitex and thriftgo WITHOUT thrift streaming support | ||
function generate_old() { | ||
echo -e "\n\ngenerate_old\n" | ||
dir=$OLD | ||
export PATH=$OLD:$SAVE_PATH | ||
|
||
mkdir -p $dir | ||
GOBIN=$dir go install github.com/cloudwego/kitex/tool/cmd/[email protected] | ||
GOBIN=$dir go install github.com/cloudwego/[email protected] | ||
if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then | ||
echo "[old] Unable to install kitex or thriftgo to $dir, please check before continue." | ||
exit 1 | ||
fi | ||
|
||
# Thrift Old | ||
rm -rf kitex_gen_old | ||
kitex -gen-path kitex_gen_old $module $idl | ||
} | ||
|
||
function generate_new() { | ||
echo -e "\n\ngenerate_new\n" | ||
dir=$NEW | ||
export PATH=$dir:$SAVE_PATH | ||
|
||
mkdir -p $dir | ||
if [ -d "$LOCAL_REPO" ]; then | ||
SAVE_DIR=`pwd` | ||
cd $LOCAL_REPO/tool/cmd/kitex && go build && cp kitex $dir | ||
cd $SAVE_DIR | ||
else | ||
echo -e "[ERROR] Please set local kitex directory in the environment variable $LOCAL_REPO\n" | ||
exit 1 | ||
fi | ||
GOBIN=$dir go install github.com/cloudwego/thriftgo@latest | ||
|
||
if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then | ||
echo "[new] Unable to install kitex or thriftgo to $dir, please check before continue." | ||
exit 1 | ||
fi | ||
|
||
rm -rf kitex_gen | ||
|
||
# Thrift | ||
kitex $module $idl | ||
|
||
# Thrift Slim | ||
kitex -thrift template=slim -gen-path kitex_gen_slim $module $idl | ||
|
||
# KitexPB | ||
kitex $module idl/api.proto | ||
|
||
# GRPC | ||
kitex $module idl/api_no_stream.proto | ||
} | ||
|
||
function generate_new_thriftgo_old_kitex() { | ||
echo -e "\n\ngenerate_new_thriftgo_old_kitex\n" | ||
dir=$NEW_THRIFTGO_OLD_KITEX | ||
export PATH=$dir:$SAVE_PATH | ||
|
||
mkdir -p $dir | ||
GOBIN=$dir go install github.com/cloudwego/kitex/tool/cmd/[email protected] | ||
GOBIN=$dir go install github.com/cloudwego/thriftgo@latest | ||
if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then | ||
echo "[cross] Unable to install kitex or thriftgo to $dir, please check before continue." | ||
exit 1 | ||
fi | ||
|
||
rm -rf kitex_gen_cross | ||
# Thrift | ||
kitex -gen-path kitex_gen_cross $module $idl | ||
} | ||
|
||
generate_new | ||
|
||
generate_new_thriftgo_old_kitex | ||
|
||
# regenerate kitex_gen_old (using kitex 0.8.0/thriftgo 0.3.4 without thrift-streaming support) | ||
if [ ! -z "$TEST_GENERATE_OLD" ]; then | ||
generate_old | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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" | ||
"strconv" | ||
|
||
"github.com/cloudwego/kitex/pkg/klog" | ||
|
||
"github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" | ||
) | ||
|
||
type GRPCPBServiceImpl struct{} | ||
|
||
func (G *GRPCPBServiceImpl) Echo(stream grpc_pb.PBService_EchoServer) (err error) { | ||
klog.Infof("[GRPCPBServiceImpl.Echo] Echo called") | ||
count := GetInt(stream.Context(), KeyCount, 0) | ||
klog.Infof("count: %d", count) | ||
for i := 0; i < count; i++ { | ||
var req *grpc_pb.Request | ||
if req, err = stream.Recv(); err != nil { | ||
klog.Infof("[GRPCPBServiceImpl.Echo] recv error: %v", err) | ||
return err | ||
} | ||
klog.Infof("[GRPCPBServiceImpl.Echo] recv success: %s", req.Message) | ||
|
||
resp := &grpc_pb.Response{ | ||
Message: req.Message, | ||
} | ||
if err = stream.Send(resp); err != nil { | ||
klog.Infof("[GRPCPBServiceImpl.Echo] send error: %v", err) | ||
return | ||
} | ||
klog.Infof("[GRPCPBServiceImpl.Echo] send success: %v", resp) | ||
} | ||
return | ||
} | ||
|
||
func (G *GRPCPBServiceImpl) EchoClient(stream grpc_pb.PBService_EchoClientServer) (err error) { | ||
klog.Infof("[GRPCPBServiceImpl.EchoClient] EchoClient called") | ||
count := GetInt(stream.Context(), KeyCount, 0) | ||
klog.Infof("count: %d", count) | ||
for i := 0; i < count; i++ { | ||
var req *grpc_pb.Request | ||
if req, err = stream.Recv(); err != nil { | ||
klog.Infof("[GRPCPBServiceImpl.EchoClient] recv error: %v", err) | ||
return err | ||
} | ||
klog.Infof("[GRPCPBServiceImpl.EchoClient] recv success: %s", req.Message) | ||
} | ||
|
||
resp := &grpc_pb.Response{ | ||
Message: strconv.Itoa(count), | ||
} | ||
err = stream.SendAndClose(resp) | ||
klog.Infof("[GRPCPBServiceImpl.EchoClient] send: err = %v, resp = %v", err, resp) | ||
return err | ||
} | ||
|
||
func (G *GRPCPBServiceImpl) EchoServer(req *grpc_pb.Request, stream grpc_pb.PBService_EchoServerServer) (err error) { | ||
klog.Infof("[GRPCPBServiceImpl.EchoServer] recv req = %s", req.Message) | ||
count := GetInt(stream.Context(), KeyCount, 0) | ||
klog.Infof("count: %d", count) | ||
for i := 0; i < count; i++ { | ||
resp := &grpc_pb.Response{ | ||
Message: req.Message + "-" + strconv.Itoa(i), | ||
} | ||
if err = stream.Send(resp); err != nil { | ||
klog.Infof("[GRPCPBServiceImpl.EchoServer] send error: %v", err) | ||
return err | ||
} | ||
klog.Infof("[GRPCPBServiceImpl.EchoServer] send success: %s", resp.Message) | ||
} | ||
return nil | ||
} | ||
|
||
func (G *GRPCPBServiceImpl) EchoPingPong(ctx context.Context, req *grpc_pb.Request) (resp *grpc_pb.Response, err error) { | ||
klog.Infof("[GRPCPBServiceImpl.EchoPingPong] recv: %s", req.Message) | ||
resp = &grpc_pb.Response{ | ||
Message: req.Message, | ||
} | ||
klog.Infof("[GRPCPBServiceImpl.EchoPingPong] send: %s", resp.Message) | ||
return resp, nil | ||
} |
Oops, something went wrong.