package main import ( "fmt" ) type A struct { field1 string } type B struct { field1 string } func main() { a := A{ field1: "aaa", } b := B(a) fmt.Printf("%#v\n", b) }
zzh@ZZHPC:~/zd/Github/ztest$ go run main.go main.B{field1:"aaa"}
A and B must have same fields (equal fields number, same names, same types).