proto best

This commit is contained in:
eson 2023-10-24 11:20:42 +08:00
parent e851a4b43c
commit 60b6064e1d
2 changed files with 48 additions and 11 deletions

View File

@ -1,13 +1,49 @@
#! /bin/bash
NAME=auth
GO_PB_PATH=./gen/go/service/$NAME
check_imports() {
# 获取所有导入语句中的 service.* 文件
import_files=$(grep -E 'import ".*\.proto"' "$1" | awk -F'"' '{print $2}')
# 定义正则表达式匹配规则
pattern="^(\.\/)?([a-zA-Z_-]+\.proto)$"
# 声明数组变量
result=()
# 列出导入的 service.* 文件
for file in $import_files; do
if [[ $file =~ $pattern ]]; then
# 去除前缀 ./ 并添加到结果数组
result+=("${BASH_REMATCH[2]}")
fi
done
# 去重结果数组中的值
unique_result=($(echo "${result[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
# 返回去重后的结果数组
echo "${unique_result[@]}"
}
PROTO_DIR=./proto
SERVICE_NAME=auth
GO_PB_PATH=./gen/go/service/$SERVICE_NAME
mkdir $GO_PB_PATH -p
protoc -I ./proto --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $NAME.proto
NAME=basic
GO_PB_PATH=./gen/go/service/$NAME
mkdir $GO_PB_PATH -p
protoc -I ./proto --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $NAME.proto
protoc -I $PROTO_DIR --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $SERVICE_NAME.proto
imports=$(check_imports $PROTO_DIR/$SERVICE_NAME.proto)
# $imports=(basic aa bb)
for import_file in $imports; do
SERVICE_NAME="${import_file%%.*}"
echo $SERVICE_NAME
GO_PB_PATH=./gen/go/service/$SERVICE_NAME
mkdir $GO_PB_PATH -p
protoc -I $PROTO_DIR --go_out $GO_PB_PATH --go_opt paths=source_relative --go-grpc_out $GO_PB_PATH --go-grpc_opt paths=source_relative --grpc-gateway_out $GO_PB_PATH --grpc-gateway_opt paths=source_relative $SERVICE_NAME.proto
done

View File

@ -5,19 +5,20 @@ option go_package = "fusen-auth/gen/go/auth";
// google/api/annotations.proto
import "google/api/annotations.proto";
import "service/basic.proto";
import "basic.proto";
//
service AuthService {
//
rpc SayHello (AuthRequest) returns (Response) {
rpc SayHello (AuthRequest) returns (service.basic.Response) {
//http网关注解
option (google.api.http) = {
post: "/api/auth/example/echo"
post: "/api/auth/echo"
body: "*"
};
}
rpc SayHelloAgain (AuthRequest) returns (Response) {}
rpc SayHelloAgain (AuthRequest) returns (service.basic.Response) {}
}
// .