-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Generate methods on an existing type #169
Comments
Could you give an example, I don't understand what you mean with extra round of code generation. |
Sure, this is what I would like to do. I want to write this source: Example moved to ticket description. |
Okay. I'm not sure if that's worth the dev effort, as the alternative using functions directly e.g: var input MyObject = ...
slim := conv.ConvertToSlim(input) isn't that different as the proposed format slim := input.ConvertToSlim() If many users want this feature, I'm cool with changing my mind about this. This project https://github.com/reedom/convergen does support having the source as receiver function, maybe it fits your need. type Convergen interface {
// :recv u
ToStorage(*User) *storage.User
} generates: type User struct {
ID int
Name string
}
func (u *User) ToStorage() (dst *storage.User) {
dst = &storage.User{}
dst.ID = int64(u.ID)
dst.Name = u.Name
return
} https://github.com/reedom/convergen?tab=readme-ov-file#recv-var |
Describe the solution you'd like
I would like to generate methods on an existing type so the type implements an interface I am defining.
and have
goverter
generate the following:Describe alternatives you've considered
I can define the methods manually and call the goverter-generated functions from them, but I would prefer to combine those steps to avoid an extra round of code generation.
Please 👍 this issue if you want this functionality. If you have a specific use-case in mind, feel free to comment it.
The text was updated successfully, but these errors were encountered: