-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Mapping context values #68
Comments
@jmattheis can I hope that this feature will be implemented once upon a time? |
@pavelpatrin Yes, but it doesn't have a high priority on my to-do list. |
Hi, a made a beta version for that , it add "arguments", is a custom structure, that can be used in internal functions, say me a opinion, maybe some improvements, for me is all what i need https://github.com/becash/goverter |
Hey @becash, it seems like the beta version has hardcoded the If any of these tickets are implemented they should built the foundation to support this otherwise it probably has to be rewritten afterwards. |
of course is a beta, about type name , is need to put in config? also need to indicate import path, maybe can you recomend a beter way |
Types that are context should be inferred from the conversion method signature.
Internally we can mark the |
The feature is WIP, you can try out it out by getting the context branch from this repository. E.g.
With this version you can specify additional parameters with the prefix Here is an example: package example
import "time"
// goverter:converter
// goverter:extend FormatTime
type Converter interface {
Convert(source map[string]Input, ctxFormat string) map[string]Output
}
func FormatTime(t time.Time, ctxFormat string) string {
return t.Format(ctxFormat)
}
type Input struct {
Name string
CreatedAt time.Time
}
type Output struct {
Name string
CreatedAt string
} You can find more examples here: https://github.com/jmattheis/goverter/blob/context/docs/reference/signature.md It'll probably take some time until this will be merged, as I likely will include #147 in the same release because this feature also adjusts how goverter parses the conversion method signature. Feedback is always welcome (:. |
Goverter should allow passing a mapping context through converter methods for custom conversions. This allows more customizability when the conversion requires other state. See also https://mapstruct.org/documentation/stable/api/org/mapstruct/Context.html
Example:
Conversion contexts are additional parameters that are passed into the conversion methods (See Convert method from Converter), and they should be passed into custom methods (See LookupUser).
This feature is WIP, see #68 (comment) for instructions to try it out.
Please 👍 this issue if you like 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: