r3labs / diff

A library for diffing golang structures
Mozilla Public License 2.0
888 stars 80 forks source link

When Bool type = false, is missing from Type:create #98

Open CIpherWGO opened 1 year ago

CIpherWGO commented 1 year ago

Hi

Test code using go 1.20:

type Test struct {
    ID   int64  `diff:"id,identifier"`
    Bool bool   `diff:"bool"`
    Test string `diff:"test"`
}

a := []Test{{ID: 1, Bool: true, Test: "Bool set to true"}}

b := []Test{{ID: 2, Bool: false, Test: "Bool set to false"}}

changelog, err := diff.Diff(a, b)

if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v\n", changelog)

Gives:

  {Type:create Path:[2 id] From:<nil> To:2 parent:<nil>} {Type:create Path:[2 test] From:<nil> To:Bool set to false parent:<nil>}]

Field Bool is missing from create. Should also have:

  {Type:create Path:[2 bool] From:<nil> To:false parent:<nil>}

Any help is appreciated!

Thanks.