I am generating Go code from a ProtoBuffer enumeration. The ProtoBuffer enum is properly named and cased, but the generated Go code has malformed variant names. The Go type, "AccessTier" is prefixed to the correct variant name, such as "ACCESS_TIER_ARCHIVE". The correct name should simply be "ACCESS_TIER_ARCHIVE". How can I configure the ProtoBuffer tool or buf.Build to generate the properly named enum variants?
I found the following issue, but it is still open. I am hoping that someone may have a suggestion about how to fix it.
https://github.com/golang/protobuf/issues/513
Thank you for your help and interest, Mike
buf.gen.yaml:
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/abcd/abcdapis/gen
except:
- buf.build/googleapis/googleapis
plugins:
- plugin: buf.build/bufbuild/connect-go
out: gen
opt: paths=source_relative
- plugin: buf.build/bufbuild/validate-go:v1.0.2
out: gen
opt:
- paths=source_relative
- plugin: buf.build/protocolbuffers/go
out: gen
opt:
- paths=source_relative
ProtoBuffer enum:
syntax = "proto3";
package abcd.enum.v5;
enum AccessTier {
ACCESS_TIER_UNSPECIFIED = 0;
ACCESS_TIER_ARCHIVE = 1;
ACCESS_TIER_COOL = 2;
ACCESS_TIER_HOT = 3;
}
The generated Go code:
type AccessTier int32
const (
AccessTier_ACCESS_TIER_UNSPECIFIED AccessTier = 0
AccessTier_ACCESS_TIER_ARCHIVE AccessTier = 1
AccessTier_ACCESS_TIER_COOL AccessTier = 2
AccessTier_ACCESS_TIER_HOT AccessTier = 3
)
// Enum value maps for AccessTier.
var (
AccessTier_name = map[int32]string{
0: "ACCESS_TIER_UNSPECIFIED",
1: "ACCESS_TIER_ARCHIVE",
2: "ACCESS_TIER_COOL",
3: "ACCESS_TIER_HOT",
}
AccessTier_value = map[string]int32{
"ACCESS_TIER_UNSPECIFIED": 0,
"ACCESS_TIER_ARCHIVE": 1,
"ACCESS_TIER_COOL": 2,
"ACCESS_TIER_HOT": 3,
}
)