Skip to content

Commit

Permalink
Update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Jul 12, 2019
1 parent 4357447 commit cbe6b6c
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,51 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/onrik/magic)](https://goreportcard.com/report/github.com/onrik/magic)
[![GoDoc](https://godoc.org/github.com/onrik/magic?status.svg)](https://godoc.org/github.com/onrik/magic)

Magic converter
## Magic converter for differect structs
By default:
1. Map same types with same names
1. Map slices with same types
1. Map types to pointers and backwards (for example: int to *int)
1. Returns error on types mismatch

By options:
1. Custom converters for different types
1. Custom mapping for different fields names

Examples:
```go
package main

import (
"fmt"

"github.com/onrik/magic"
)

type User1 struct {
ID int
Name string
Password string
Age int
}

type User2 struct {
ID int
Name string
Age *int
}

func main() {
user1 := User1{
ID: 1,
Name: "John",
Password: "111",
Age: 21,
}
user2 := User2{}

err := magic.Map(user1, &user2)
fmt.Println(err)
fmt.Printf("%+v\n", user2)
}
```

0 comments on commit cbe6b6c

Please sign in to comment.