Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to merge when using a pointer to a struct #6

Closed
worg opened this issue Sep 7, 2014 · 3 comments
Closed

Fails to merge when using a pointer to a struct #6

worg opened this issue Sep 7, 2014 · 3 comments

Comments

@worg
Copy link

worg commented Sep 7, 2014

I don't seem to find out why the tests pass in stuff like complexTest but fails to merge correctly stuff like the following:

package main

import (
    "fmt"
    "github.com/imdario/mergo"
)

type Person struct {
    ID      int
    Name    string
    Address string
}

var defaultPerson = Person{
    ID:      1,
    Name:    "Homer",
    Address: "742 Evergreen Terrace",
}

func main() {
    a := Person{Name: `John`}
    if err := mergo.Merge(&a, defaultPerson); err != nil {
        fmt.Printf("ERR: %+v", err)
    }

    fmt.Printf("A is: %+v\n", a)
    // Prints A is: {ID:1 Name:Homer Address:742 Evergreen Terrace}
    // should print A is: {ID:1 Name:John Address:742 Evergreen Terrace}
}
@lintianzhi
Copy link

I think function Merge means merge all no empty values in dest to src. so the example should like this:

func main() {
    a := defaultPerson
    if err := mergo.Merge(&a, Person{Name: `John`}); err != nil {
        fmt.Printf("ERR: %+v", err)
    }

    fmt.Printf("A is: %+v %v\n", a)
}

PS. i like the strategy merge when src‘s value is empty

@worg
Copy link
Author

worg commented Oct 14, 2014

Oh… I might have misunderstood, I wanted to merge all no empty values from src into dest, so closing this issue.
Thanks!

@worg worg closed this as completed Oct 14, 2014
@darccio
Copy link
Owner

darccio commented Dec 6, 2014

Thanks @lintianzhi for taking care of this issue. Merge works like you said 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants