Csharp

  1. 安装Grpc.tools https://www.nuget.org/packages/Grpc.Tools/

  2. 下载解压 nupkg文件(改扩展名为zip),也可以使用附件的7z包

  3. 解压 找到tools中对应系统架构的软件,设置下环境变量,让系统可以找到就行。

Linux 需要创建一个符号链接

ln -s `which grpc_csharp_plugin` /usr/bin/protoc-gen-grpc-csharp
  1. 修改Kratos项目的Make文件

在api这个make任务中添加下面内容

         --csharp_out=./api/pipe/v1 \
         --grpc-csharp_out=./api/pipe/v1 \

完整内容为

.PHONY: api
# generate api proto
api:
 protoc --proto_path=./api \
        --proto_path=./third_party \
         --go_out=paths=source_relative:./api \
         --go-http_out=paths=source_relative:./api \
         --go-grpc_out=paths=source_relative:./api \
         --csharp_out=./api/pipe/v1 \
         --grpc-csharp_out=./api/pipe/v1 \
         --openapi_out==paths=source_relative:. \

参考

https://github.com/grpc/grpc/blob/master/src/csharp/BUILD-INTEGRATION.md

📎tools.7z

Python

  1. 安装必要包 pip install grpclib protobuf
  2. 查询路径 which protoc-gen-grpclib_python 或者 which protoc-gen-python_grpc我这里返回信息如下:
➜  czyt which protoc-gen-grpclib_python
/usr/sbin/protoc-gen-grpclib_python
  1. 如法炮制,创建软链接
ln -s /usr/sbin/protoc-gen-grpclib_python /usr/sbin/protoc-gen-grpc_python
  1. 修改Makefile 添加下面的内容,再执行make api生成api即可。
--python_out=./api \
--grpc_python_out=./api \

Dart

  1. 安装插件
dart pub global activate protoc_plugin
  1. 将插件工具加入环境变量
export PATH="$PATH:$HOME/.pub-cache/bin"
  1. 脚本添加--dart_out=选项
--dart_out=./api \

TypeScript

纯typescript类

typescript类+服务

  1. 安装proto工具 go get go.einride.tri p tech/protoc-gen-typescript-http

  2. 在MakeFile中添加一行

      --typescript-http_out [OUTPUT DIR] \
      [.proto files ...]
    
  3. 生成的示例代码

    const rootUrl = "...";
    
    type Request = {
      path: string,
      method: string,
      body: string | null
    }
    
    function fetchRequestHandler({path, method, body}: Request) {
      return fetch(rootUrl + path, {method, body}).then(response => response.json())
    }
    
    export function siteClient() {
      return createShipperServiceClient(fetchRequestHandler);
    }
    

    其他