Closed lvhuat closed 3 months ago
Protos should always use a dedicated package and not share that package with non proto-generated Go code. I am closing this, because I am pretty sure that's the reason here. Please reopen if this also happens with using a dedicate package for the proto generated code.
Yes, it has to do with in-package init ordering. It’s resolved by spinning your protobuf relevant code out into its own package (as has already been said).
What version of protobuf and what language are you using? protobuf version: v1.5.4 language: golang
What did you do? Use Enum String to init variable in package.
What did you expect to see? Process start smoothly
What did you see instead? Panic when call enumItem.String()
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
enum.proto
main.go
Print info:
Anything else we should know about your project / environment? $ go version go version go1.22.5 linux/amd64
$ protoc --version libprotoc 26.1
$ protoc-gen-go --version protoc-gen-go v1.34.2
My Guess After golang 1.21, golang has changed its initial order https://tip.golang.org/doc/go1.21