当前位置: 首页 > 工具软件 > Copier > 使用案例 >

golang结构体拷贝jinzhu/copier

夏长卿
2023-12-01

package main

import (
“fmt”
“github.com/jinzhu/copier”
)

type User struct {
Name string json:"name"
Age int json:"age"
Location string json:"location"
}

func main() {
user1 := User{Name: “John Doe”, Age: 30, Location: “New York”}
user2 := User{}

// Copy fields with same JSON tag using copier package
copier.Copy(&user2, &user1)

fmt.Println(user2)

}

 类似资料: