-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add type option #61
Add type option #61
Conversation
a16c2e5
to
416f079
Compare
@ydnar, I have allowed edits by maintainers, feel free to refactor as much as you think it needs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty impressive. I'm in a phone so can't test it, but I'm generally inclined to accept this PR with some changes.
Thanks!
@Adphi can it support slices of imported types? e.g.: message CastTypeMessage {
repeated string names = 1 [(go.field).casttype = "[]github.com/user/module/pkg.Name"]
} |
There was an issue with the package import generation, it is fixed. |
8ff3ef2
to
f607bf3
Compare
Got it. Given that Go supports type aliases, where What do you think? |
Can you fix the go vet issues? |
Actually, It's not about type alias ( |
|
Sorry, I meant using type aliases for types declared in other packages. Rather than have package myproto
import "github.com/org/repo"
type A = repo.A This should make the implementation in |
@ydnar I'm sorry, I don't understand why you would want to use type aliases. I think I must have explained myself wrong. There is no problem with external package imports: please take a look at the plugin tests' generated code. |
Oh, I know that it works. But it adds complexity to both the plugin interface and the implementation. Is there any functionality that requires external package imports? |
For example: I am working on multiple active directory based projects divided into several libraries, active directory uses an attribute called userAccountControl to store security related flags. The library defines the |
Got it. Can you add a single Go file that aliases package foo
import "github.com/Adphi/ws"
type UserAccountControl = ws.UserAccountControl |
Of course I can 😉. But I don't see any reason to do it as protopatch would allow to use the original type, and the implementation in protopatch is pretty straight forward... |
My concerns are three-fold:
I’d consider it if you could split out foreign types into a separate follow-up PR that we can evaluate in isolation. I agree that it provides some nice ergonomics to declare a fully-qualified type, but my concerns outlined above make me wary. |
@ydnar Thanks for the detailed explanation. I'll move external packages support into another pull request. |
@Adphi is the description in this PR up to date with the functionality? e.g. has fully-qualified types and |
It should be now 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a few more comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close! Looking forward to merging this one.
@Adphi can you rebase this against current |
@ydnar it's done. |
patch/go.proto
Outdated
@@ -21,6 +21,10 @@ message Options { | |||
// See https://golang.org/ref/spec#Struct_types. | |||
optional bool embed = 2; | |||
|
|||
// The type option changes the generated field type. | |||
// All generated code assumes that this type is castable to the protocol buffer field type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// All generated code assumes that this type is castable to the protocol buffer field type, | |
// All generated code assumes that this type is castable to the protocol buffer field type. |
@Adphi merged and released in v0.5.0. Could you make a follow-up PR that adds documentation for the |
This pull request add a
type
field option:scalar fields support
repeated fields support: