-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature request: Add setters #65
Comments
Nope. The code bloat does not warrant the minor utility, which you can achieve with your own wrapper types, or with reflection. |
Are you sure we can't discuss this? I don't see this as minor, I have the exact same issue, want to set ResponseID from RequestID. Alternatively, and this may already exist, could there be / is there already a way to add a hook for 'extra' parts like setters? |
+1 |
@dsymonds With due respect, that's an obnoxiously terse response to a legitimate request. If it was so easy @ekle would not have asked. I expect you'll close the discussion next? This is typical golang community "you're a bad programmer for asking" behavior; we can be better than that. Let's discuss this like engineers. In response to your assertions:
Manually writing wrappers for all messages is a terrible solution; generating them is marginally better but both are a large amount of non-trivial work for a problem easily and naturally solved in this library: Adding setters. |
In the spirit of showing my work, this patch was sufficient to get my project moving again, and I was able to eliminate a lot redundant functions with a two line interface as a result. |
@jspiro thats a cool patch. at the moment i'm using a big Makefile with some bash/grep magic to transform the existing getters to setters in a new file. |
@jspiro, I don't think it's helpful to summarize @dsymonds as simply saying "you're a bad programmer for asking" since he says nothing of the sort. Even if someone closes the issue, you can always respond back with more discussion points as you have done here. Points to consider:
/cc @alandonovan, who is interested in protobuf reflection. |
See #364. |
I've been working on #364 and I am convinced that is the right solution for the root issues going on here. I understand the temptation want to use Go interfaces to set some generic field in a set of messages, but it makes the very subtle assumption that all of them will have the same method signature, which is not a world we want to back ourselves into. |
I ran into this issue today and wrote a little protoc generator for setters. Thought I'd share: Still a WIP. Right now it supports primitive types. Working on adding more complex types. |
why dont you support setter. |
and how can i use the interface feature of golang to protobuf messages? |
We’re reworking the way proto reflection works, and it should support better abstract interactions with messages. But typically Go prefers less abstraction… maybe you’re trying to abstract too much? |
i just abstract one public operation of one field of ten or more structures. my implemetion: rpc input -> grpc server(internal Dispatch) -> grpc server impl (my code)->grpc server impl : routine (my code, i need abstruct common api to two field from different implemetion: int success, string errorMsg. )-> acturtal implemetion for rpc suitiuation, we need keep rpc api/protocal stable. and implement different backend . so we dont want to expose different api set for different backend implemention. or i must write much if/else in routine code for keeping only one api set without Setter interface. |
A central concept of golang is to not abstract things unnecessarily. In general, you should be avoiding adding layers of abstraction unless you find it extremely difficult not to. As such, each RPC should have a discrete, individual, and specific Having two fields P.S.: If you have named your field |
generated message-types have only getters but no setters at the moment.
This makes it impossible to create an interface which can change values of them.
This would be especially useful for the return messages of rpc calls.
For example a generic function which adds an request-id to every response.
The text was updated successfully, but these errors were encountered: