问题
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