https://github.com/tamboto2000/mapper
Mapper map struct to another struct
https://github.com/tamboto2000/mapper
mapper struct-mapping
Last synced: 3 months ago
JSON representation
Mapper map struct to another struct
- Host: GitHub
- URL: https://github.com/tamboto2000/mapper
- Owner: tamboto2000
- License: mit
- Created: 2020-12-04T12:10:35.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-08T21:56:59.000Z (over 5 years ago)
- Last Synced: 2023-07-27T22:41:20.687Z (almost 3 years ago)
- Topics: mapper, struct-mapping
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mapper
[](https://pkg.go.dev/github.com/tamboto2000/mapper)
Mapper map struct to another struct with same or similiar fields.
### Installation
Mapper require Go version 1.14 or up
```sh
$ go get github.com/tamboto2000/mapper
```
### Example
```go
package main
import (
"fmt"
"github.com/tamboto2000/mapper"
)
type Struct1 struct {
Str string
Num int
Float float64
}
type Struct2 struct {
Str string
Num int
}
func main() {
struct1 := Struct1{Str: "Hello world!", Num: 1, Float: 1.5}
struct2 := new(Struct2)
if err := mapper.Map(struct1, struct2); err != nil {
panic(err.Error())
}
fmt.Println("Str:", struct2.Str)
fmt.Println("Num:", struct2.Num)
}
```
License
----
MIT