Optional support in Proto3 for Go
Asked Answered
E

1

5

Does optional supports in proto3 while working with Go? I tried with this:

protoc person.proto --go_out=. --experimental_allow_proto3_optional

but got this error

person.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-go hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--go_out:

so proto3 (Go) does not support optional keyword?

Ephrayim answered 19/10, 2021 at 12:39 Comment(0)
T
7

protoc does support it, starting from version v3.15.0. See the release notes:

Optional fields for proto3 are enabled by default, and no longer require the --experimental_allow_proto3_optional flag.

The protoc-gen-go plugin does starting from v1.22.0. Release notes:

This release adds support for the experimental proto3 optional semantics coming in the v3.12.0 release of the protobuf language, [...]

Make sure to upgrade your protoc-gen-go to version v1.22.0 or above.

Tobi answered 19/10, 2021 at 12:46 Comment(3)
pkg.go.dev/github.com/golang/protobuf/… is this deprecatedEphrayim
@Ephrayim yes, the current library is github.com/protocolbuffers/protobuf-go (module name google.golang.org/protobuf)Tobi
I am getting same issue(optional type) with github.com/nats-rpc/nrpcHangnail

© 2022 - 2025 — McMap. All rights reserved.