Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare is used to compare two different values and spot the differences from them
Example (Struct) ¶
package main import ( "context" "fmt" "github.com/haritsfahreza/libra" ) type person struct { ID int `libra:"id"` Name string Age int Weight float64 IsMarried bool Hobbies []string Numbers []int Ignore string `libra:"ignore"` Interface interface{} } func main() { oldPerson := person{ Name: "Gopher", Age: 10, Weight: 50.0, IsMarried: false, Hobbies: []string{"Coding"}, Numbers: []int{0, 1, 2}, } newPerson := person{ Name: "Gopher", Age: 10, Weight: 60.0, IsMarried: false, Hobbies: []string{"Hacking"}, Numbers: []int{1, 2, 3}, } diffs, err := libra.Compare(context.Background(), oldPerson, newPerson) if err != nil { panic(err) } for i, diff := range diffs { fmt.Printf("#%d : ChangeType=%s Field=%s ObjectType=%s Old='%v' New='%v'\n", i, diff.ChangeType, diff.Field, diff.ObjectType, diff.Old, diff.New) } }
Output: #0 : ChangeType=changed Field=Weight ObjectType=libra_test.person Old='50' New='60' #1 : ChangeType=changed Field=Hobbies ObjectType=libra_test.person Old='Coding' New='Hacking' #2 : ChangeType=changed Field=Numbers ObjectType=libra_test.person Old='0,1,2' New='1,2,3'
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.