go-proto-validators
go-proto-validators copied to clipboard
Variable import order caused by "option go_package" in conjunction with "import"
When one or both of the option go_package
lines in the below 2 files are enabled, the import order changes randomly between:
_ "." // or "github.com/someuser/api_a"
_ "github.com/mwitkow/go-proto-validators"
and vice versa.
File: a.proto
syntax = "proto3";
package a;
// option go_package = "github.com/someuser/api_a";
message Thing { string id = 1; }
File: b.proto
syntax = "proto3";
import "a.proto";
package b;
// option go_package = "github.com/someuser/api_b";
import "github.com/mwitkow/go-proto-validators/validator.proto";
message SomethingContainingThing { a.Thing thing = 1 [(validator.field) = {msg_exists : true}]; }
Makefile
default: b.validator.pb.go b.pb.go
%.validator.pb.go: %.proto a.proto
@protoc -I. -Ivendor -Ivendor/github.com/protocolbuffers/protobuf/src --govalidators_out=paths=source_relative:. "$<"
%.pb.go: %.proto a.proto
@protoc -I. -Ivendor -Ivendor/github.com/protocolbuffers/protobuf/src --go_out=paths=source_relative:. "$<"
.PHONY: clean
clean:
@rm -f *.pb.go
Script to highlight flake
F="b.validator.pb.go"
while true ; do
rm -f "$F"
make "$F"
md5="$(md5sum "$F" | awk '{print $1}')"
echo -e "$(date)\t$md5"
mv "$F "$md5-$F"
done
(If F
is changed to b.pb.go
, no flakiness is observed in the output.)
In the vendor
dir we have:
tree -d vendor
vendor/
└── github.com
├── google
│ └── protobuf
│ └── src
│ └── google
│ └── protobuf
│ ├── compiler
│ │ ├── cpp
│ │ └── ruby
│ └── util
│ └── internal
│ └── testdata
└── mwitkow
└── go-proto-validators
├── examples
└── test
Versions:
- mwitkow/go-proto-validators is at 1f38828 (28/Mar/2019)
- protocolbuffers/protobuf is at
f425b9f
(12/Feb/2019, orv3.7.0+incompatible
according togo.mod
)
Fix here https://github.com/gogo/protobuf/pull/700