Golang embedded struct type

后端 未结 3 1340
醉话见心
醉话见心 2020-12-03 03:07

I have these types:

type Value interface{}

type NamedValue struct {
    Name  string
    Value Value
}

type ErrorValue struct {
    NamedValue
    Error er         


        
3条回答
  •  没有蜡笔的小新
    2020-12-03 03:31

    In addition to the wonderful answer by icza.

    you can simply do this:

    v := NamedValue{Name: "fine", Value: 33}
    e := ErrorValue{NamedValue:v, Error: err}
    

    and it works just fine. checkout the example Here

提交回复
热议问题