This package holds helpers for better parses among structs.
This method reutrns a new instance of Mapper.
This interface contains one method only:
// From creates map from source
type Mapper interface {
From(src interface{}) Result
}
This interface contains two methods only:
// From creates map from source
type Result interface {
Merge(src interface{}) Result
To(tgr interface{}) error
}
This method returns the map Result
interface.
Example:
// mapping some entity
result := mapper.From(entity)
This method returns the merged map Result
interface.
// merging some entity
result := result.Merge(entity)
This method receive a pointer as parameter and returns error.
// mapping to some target
err := result.To(&target)
if err != nil {
fmt.Println(err)
}
Note: You can use this methods combined.
Example
err := mapper.From(source).To(&target)
if err != nil {
fmt.Println(err)
}
The tag mapper
allow you mapping fields with diferents names.
*Example Mapping field Sources from Source to Targes from Target
type Source struct {
Name string
List []string
Sources []Source
}
type Target struct {
Name string
List []string
Targets []Target `mapper:"Sources"`
}