mirror of
https://github.com/luxfi/zapdb.git
synced 2026-07-27 06:54:45 +00:00
pb: avoid protobuf warning due to common filename (#1519)
If a Go program imports both badger (v1) and badger/v2, a warning will be produced at init time: WARNING: proto: file "pb.proto" is already registered A future release will panic on registration conflicts. See: https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict The problem is the "pb.proto" filename; it's registered globally, which makes it very likely to cause conflicts with other protobuf-generated packages in a Go binary. Coincidentally, this is a problem with badger's pb package in the v1 module, since that too uses the name "pb.proto". Instead, call the file "badgerpb2.proto", which should be unique enough, and it's also the name we use for the Protobuf package. Finally, update gen.sh to work out of the box via just "bash gen.sh" without needing extra tweaks, thanks to the "paths=source_relative" option. It forces output files to be produced next to the input files, which is what we want.
This commit is contained in:
+210
-210
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Run this script from its directory, so that badgerpb2.proto is where it's expected to
|
||||
# be.
|
||||
|
||||
# You might need to go get -v github.com/gogo/protobuf/...
|
||||
|
||||
protos=${GOPATH-$HOME/go}/src/github.com/dgraph-io/badger/pb
|
||||
pushd $protos > /dev/null
|
||||
protoc --gofast_out=plugins=grpc:. -I=. pb.proto
|
||||
|
||||
# Move pb.pb.go file to the correct directory. This is necessary because protoc
|
||||
# would generate the pb.pb.go file inside a different directory.
|
||||
mv $protos/github.com/dgraph-io/badger/v2/pb/pb.pb.go ./
|
||||
protoc --gofast_out=plugins=grpc:. --gofast_opt=paths=source_relative -I=. badgerpb2.proto
|
||||
|
||||
Reference in New Issue
Block a user