https://github.com/juntaki/mapto
struct private field's value mapping for Clean architecture (experimental)
https://github.com/juntaki/mapto
Last synced: 7 months ago
JSON representation
struct private field's value mapping for Clean architecture (experimental)
- Host: GitHub
- URL: https://github.com/juntaki/mapto
- Owner: juntaki
- License: mit
- Created: 2019-09-07T01:28:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-07T03:28:24.000Z (about 6 years ago)
- Last Synced: 2025-02-06T04:46:51.805Z (9 months ago)
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mapto
You may want to keep the structure field private, but you must map the value to the target structure.
Making a lot of getters is one of the solutions, but you can keep the source code short with a few hacks.# How to use
https://play.golang.org/p/BSQJZQ8U0Ya
```
go get github.com/juntaki/mapto
```Source struct (with private fields)
```
type SrcStruct struct {
p1 string
}
```target (with "mapto" tag)
```
type destStruct struct {
P1 string `mapto:"p1"`
}
```Do the hack
```
src := testpkg.NewSrcStruct("p1")
dest := &destStruct{}mapto.Map(dest, src)
fmt.Println(dest.P1) // "p1"
```