<p>Coming from C# .NET MVC background, I appreciate the utility of AutoMapper that maps my domain model with DTO. This significantly relieves the burden of mapping objects.</p>
<p>Currently, I am working on my personal project that employs layered design. I am using DTO for client-side data representation. To be honest, my DTO is not much different from my business logic model, except certain data are removed in DTO for security reasons. I have a long list of domain objects, and each of them can be mapped to a variety of DTOs depending on the use case, and writing these mapper functions is tedious.</p>
<p>So, do any of you know if there is any sort of mappers that can (partially) reduce the workload of writing mapper functions? Thanks! </p>
<hr/>**评论:**<br/><br/>epiris: <pre><p>Oh my.. you want to serve bytes right? So do that. Add abstractions when doing that becomes tedious. Don't start software design at the abstractions. If you need help while serving your bytes than explain the <strong>problem</strong> here, not the solution you have chosen.. or in this case the entire abstract domain of the solution you have chosen. Questions in <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem" rel="nofollow">XY problem</a> form should be avoided in general, but in Go even more so because you will find the solutions are much different (simpler) than your current background.</p></pre>gac_web: <pre><p>There are no objects in Go, only values per spec. So define 2 structs, the "object" and the DTO.</p>
<blockquote>
<p>I have a long list of domain objects, and each of them can be mapped to a variety of DTOs depending on the use case, and writing these mapper functions is tedious.</p>
</blockquote>
<p>Write a generator ( a go program) that will look at Go ast and generate your mapper function from the struct definition ? </p></pre>FUZxxl: <pre><p>First struct maps, then commute.</p></pre>
