Documentation
¶
Overview ¶
Package automapper provides struct-to-struct mapping code generation. Users register custom converters that the CLI uses during code generation.
Index ¶
- func RegisterFrom[A, B any](fn func(A) B)
- func RegisterFromE[A, B any](fn func(A) (B, error))
- func RegisterFromNamed[A, B any](name string, fn func(A) B)
- func RegisterFromNamedE[A, B any](name string, fn func(A) (B, error))
- func RegisterTo[A, B any](fn func(A) B)
- func RegisterToE[A, B any](fn func(A) (B, error))
- func RegisterToNamed[A, B any](name string, fn func(A) B)
- func RegisterToNamedE[A, B any](name string, fn func(A) (B, error))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFrom ¶
func RegisterFrom[A, B any](fn func(A) B)
RegisterFrom registers a converter function from type A to type B. The type parameter order is [source, dest], same as RegisterTo.
Example:
func init() {
automapper.RegisterFrom[int64, time.Time](UnixToTime)
}
func RegisterFromE ¶
RegisterFromE registers a converter function from type A to type B that may return an error. The type parameter order is [source, dest], same as RegisterToE.
Example:
func init() {
automapper.RegisterFromE[string, time.Time](RFC3339ToTime)
}
func RegisterFromNamed ¶
RegisterFromNamed registers a named converter function from type A to type B. The type parameter order is [source, dest], same as RegisterToNamed.
Example:
func init() {
automapper.RegisterFromNamed[int64, string]("rfc3339", RFC3339ToTime)
}
func RegisterFromNamedE ¶
RegisterFromNamedE registers a named converter function from type A to type B that may return an error. The type parameter order is [source, dest], same as RegisterToNamedE.
Example:
func init() {
automapper.RegisterFromNamedE[int64, string]("rfc3339", RFC3339ToTimeE)
}
func RegisterTo ¶
func RegisterTo[A, B any](fn func(A) B)
RegisterTo registers a converter function from type A to type B. The converter is called when generating mapping code where the source field is type A and target field is type B.
Example:
func init() {
automapper.RegisterTo[time.Time, *datepb.Date](ToDate)
}
func RegisterToE ¶
RegisterToE registers a converter function from type A to type B that may return an error.
Example:
func init() {
automapper.RegisterToE[string, int](strconv.Atoi)
}
func RegisterToNamed ¶
RegisterToNamed registers a named converter function from type A to type B. Named converters can be referenced in struct tags using map:",conv=name".
Example:
func init() {
automapper.RegisterToNamed[time.Time, string]("rfc3339", TimeToRFC3339)
}
func RegisterToNamedE ¶
RegisterToNamedE registers a named converter function from type A to type B that may return an error.
Example:
func init() {
automapper.RegisterToNamedE[time.Time, string]("rfc3339", TimeToRFC3339E)
}
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
automapper
command
Package main provides the automapper CLI.
|
Package main provides the automapper CLI. |
|
internal
|
|
|
analyzer
Package analyzer provides AST analysis for struct types and converter registrations.
|
Package analyzer provides AST analysis for struct types and converter registrations. |
|
generator
Package generator produces Go source code for struct mappers.
|
Package generator produces Go source code for struct mappers. |
|
registry
Package registry manages converter registrations for code generation.
|
Package registry manages converter registrations for code generation. |
|
resolver
Package resolver determines field mappings between struct types.
|
Package resolver determines field mappings between struct types. |