Closed krishna-birla closed 3 years ago
import "fmt" import "github.com/jinzhu/copier" type Outer struct { Inner Inner } type Inner struct { intPtr *int } type DriverOptions struct { GenOptions map[string]interface{} } func main() { intVal := 5 outer := Outer{ Inner: Inner{ intPtr: &intVal, }, } from := DriverOptions{ GenOptions: map[string]interface{}{ "key": outer, }, } to := DriverOptions{} if err := copier.Copy(&to, &from); nil != err { return } *to.GenOptions["key"].(Outer).Inner.intPtr = 6 fmt.Println(*from.GenOptions["key"].(Outer).Inner.intPtr) }
6
About your example, unexported fields cannot be copied. PR #70 adds support for copying to a map using interface.
Sample Code
Output