Golang : Is conversion between different struct types possible?

前端 未结 5 843
小蘑菇
小蘑菇 2020-12-01 00:17

Let\'s say I have two similar types set this way :

type type1 []struct {
    Field1 string
    Field2 int
}
type type2 []struct {
    Field1 string
    Field         


        
5条回答
  •  天涯浪人
    2020-12-01 00:43

    As of Go 1.8, struct tags are ignored when converting a value from one struct type to another. Types type1 and type2 will be convertible, regardless of their struct tags, in that Go release. https://beta.golang.org/doc/go1.8#language

提交回复
热议问题