亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

gRPC-Gateway 不使用 http endpoint 方法生成 resiter

gRPC-Gateway 不使用 http endpoint 方法生成 resiter

Go
一只名叫tom的貓 2022-08-24 20:11:33
我正在嘗試使用以使我的go grpc方法也可用于http調用。為此,我正在使用模塊。但是,當我使用protoc生成proto文件時,我沒有看到示例中所示的方法。這就是我的 .proto 文件的樣子https://github.com/grpc-ecosystem/grpc-gatewayhttps://github.com/grpc-ecosystem/grpc-gatewayRegister*FromEndpointsyntax = "proto3";package health;option go_package = "github.com/user/app/api/health";import "google/api/annotations.proto";service Health {    rpc Ping (HealthRequest) returns (HealthReply) {      option (google.api.http) = {        get: "/ping"      };    }  }    // The request message containing the user's name  message HealthRequest {      }    // The response message containing the greetings  message HealthReply {    string message = 1;  }這就是我的原型命令的樣子protoc --go_out=api/proto/ --go_opt=paths=source_relative \    --go-grpc_out=./api/proto --go-grpc_opt=paths=source_relative \    --proto_path=internal/api \    --proto_path=third_party \    ./internal/api/health/health.proto      生成工作正常,沒有任何錯誤,但生成的文件沒有等效方法,如此處的示例所示health_grpc.pb.goRegisterYourServiceHandlerFromEndpointhttps://github.com/grpc-ecosystem/grpc-gateway
查看完整描述

2 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

為了生成存根,我們可以使用 或 。 是業界廣泛使用的更經典的一代體驗。盡管如此,它仍有一個相當陡峭的學習曲線。 是一個較新的工具,考慮到用戶體驗和速度。它還提供起毛和破壞性變化檢測,但有些東西不提供。protocbufprotocbufprotoc

您可以在此處閱讀更多信息:https://grpc-ecosystem.github.io/grpc-gateway/docs/tutorials/generating_stubs/using_buf/。buf


查看完整回答
反對 回復 2022-08-24
?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

作為 grpc-gateway saied 的文檔,我建議你使用 buf 而不是 protoc,它更簡單友好。


您可以參考 grpc-gateway#usage 的文檔


version: v1beta1

plugins:

  - name: go

    out: gen/go

    opt:

      - paths=source_relative

  - name: go-grpc

    out: gen/go

    opt:

      - paths=source_relative

  - name: grpc-gateway

    out: gen/go

    opt:

      - paths=source_relative

      - generate_unbound_methods=true

如果你仍然想使用protoc,你需要添加參數:--grpc-gateway_opt


protoc -I . --grpc-gateway_out ./gen/go \

    --grpc-gateway_opt logtostderr=true \

    --grpc-gateway_opt paths=source_relative \

    --grpc-gateway_opt generate_unbound_methods=true \

    your/service/v1/your_service.proto


查看完整回答
反對 回復 2022-08-24
  • 2 回答
  • 0 關注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號