-
Notifications
You must be signed in to change notification settings - Fork 1.6k
proposal: protoc-gen-go: support embedding a nested type #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This isn't possible with the current code generator. Protobuf schemas are independent of language, so it would be difficult to specify the semantics you want in a language-neutral way. |
I would be fine with a language-specific option. Something like |
what sort of use case would this be used for @phifty? |
At least to provide automatic binding with chi.Render sendRequest := &mailer.SendRequest{
Sender: &mailer.Sender{},
Mail: &mailer.Mail{},
}
if err := render.Bind(r, sendRequest); err != nil {} |
I wrote the plugin to support struct embedding: #430 |
Adding support for embedding in the mainline proto repo breaks the semantics of protobufs. According to the proto language spec, there is a distinction between the zero value for a message and an unset message (even for proto3). Embedding provides no such distinctions. |
We're going to reject this for the following reasons: 1) Embedded values violates the semantics of protos. It is unclear in this proposal whether the OP intended for 2) Embedded pointers lead to brittle code. Suppose that the intended behavior was the later (i.e., 3) Embedding forwards unintended methods. When you embed 4) Embedding in Go creates portability issues over time. Imagine the following: type Parent struct {
Username
other.pkg.Bar
}
type Username struct { Name, Pass string }
var p Parent
p.Name = "dsnet" This may work fine today, but can run into compilation issue when the |
Given the code
The generated
User
struct contains than a pointer to a password struct. Is it possible to embed the struct? TheUser
would contain thePassword
(without a pointer) and thePassword
would be initialized along with theUser
.The text was updated successfully, but these errors were encountered: