dongwei8729 2017-01-22 15:15
浏览 240
已采纳

proto3->使用自定义扩展名,导致在go代码中导入到程序包(“ google / protobuf”)

I am prototyping a meta model on top of proto3. To generate domain specific boilerplate as the go proto3 extension syntax is ridiculously expressive. My domain proto files depend on meta.proto which contain the extensions.

I can compile the these to go. When including the meta.proto file the generated go ends up with the following include block:

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "google/protobuf" <--- this import does not exist !!

My extension file has the following structure(based off this):

syntax = "proto2";
package "...";

option go_package = "..."; 

import "google/protobuf/descriptor.proto"; <--- this causes the import

// message MyExtensionClass ...
// message MyExtensionField ...

extend google.protobuf.MessageOptions {
    optional MyExtensionClass class = 50000;
}

extend google.protobuf.FieldOptions {
    optional MyExtensionField field = 50001;
}

I know the solution is likely very simple, the google/protobuf include is meant for C++ generation.


In my workspace the included package should be "github.com/golang/protobuf/protoc-gen-go/descriptor"

  • 写回答

1条回答 默认 最新

  • doupo5861 2017-01-23 12:10
    关注

    Poor mans solution. Not ideal, directing it to the relevant go import works:

    sed -i '' -e 's/import google_protobuf \"google\/protobuf\"/import google_protobuf \"github.com\/golang\/protobuf\/protoc-gen-go\/descriptor\"/g' pkg/domain/proto/extensions/*.pb.go
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集