Google Protobuf dependency collision

*爱你&永不变心* 提交于 2020-03-26 02:36:45

问题


I am working on a Golang library that leverages Google Protobuf. It does so by using code auto-generated by protoc-gen-go, the compiler plugin. I am using Dep for dependency management. The generated code exports the InstanceStatusUpdate struct, for which the field Timestamp is of the type github.com/golang/protobuf/ptypes/timestamp.Timestamp:

type InstanceStatusUpdate struct {
    EvaluationId  string
    VariationId   string
    AttemptNumber int32
    Timestamp     *google_protobuf.Timestamp
    Stage         string
    Metadata      string
    JobId         string
}

The problem I have is that writing library code to populate the Timestamp field triggers a redundant auto-importing of "github.com/golang/protobuf/ptypes", since that is where the type that needs to be assigned to Timestamp lives. This redundancy causes this error:

cannot use timestamp (type *"my_path/vendor/github.com/golang/protobuf/ptypes/timestamp".Timestamp) as type *"github.com/golang/protobuf/ptypes/timestamp".Timestamp in field value

Any ideas?

library structure (only one vendor folder):

code_root
|
 -lib
|  |
|   -go-statuses
 -my_package /*Contains code that refers to the auto-generated code in 
   |          go-statuses*/
   |
    -vendor

来源:https://stackoverflow.com/questions/49823114/google-protobuf-dependency-collision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!