创建proto文件

vim calculator.proto

syntax = "proto3";

package calculator;

// 重要
option go_package = "your-username/calculator";

service CalculatorService {
    rpc Add(AddRequest) returns (AddResponse) {}
}

message AddRequest {
    int32 num1 = 1;
    int32 num2 = 2;
}

message AddResponse {
    int32 result = 1;
}

生成grpc相关的go代码

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative calculator/calculator.proto

Copyright © 运维知识库 all right reserved,powered by Gitbook文件修订时间: 2023-09-19 10:45:38

results matching ""

    No results matching ""