mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
test: add examples for CopyProperties function
This commit is contained in:
@@ -295,3 +295,45 @@ func ExampleDeepClone() {
|
|||||||
// map[a:1 b:2] false
|
// map[a:1 b:2] false
|
||||||
// &{test 1 0.1 true <nil> } false
|
// &{test 1 0.1 true <nil> } false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleCopyProperties() {
|
||||||
|
type Address struct {
|
||||||
|
Country string
|
||||||
|
ZipCode string
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Name string
|
||||||
|
Age int
|
||||||
|
Role string
|
||||||
|
Addr Address
|
||||||
|
Hobbys []string
|
||||||
|
salary int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Employee struct {
|
||||||
|
Name string
|
||||||
|
Age int
|
||||||
|
Role string
|
||||||
|
Addr Address
|
||||||
|
Hobbys []string
|
||||||
|
salary int
|
||||||
|
}
|
||||||
|
|
||||||
|
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
|
||||||
|
|
||||||
|
employee1 := Employee{}
|
||||||
|
CopyProperties(&employee1, &user)
|
||||||
|
|
||||||
|
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
|
||||||
|
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
|
||||||
|
|
||||||
|
CopyProperties(&employee2, &user)
|
||||||
|
|
||||||
|
fmt.Println(employee1)
|
||||||
|
fmt.Println(employee2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// {user001 10 Admin {CN 001} [a b] 0}
|
||||||
|
// {user001 10 Admin {CN 001} [a b] 500}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user