Go is all about composition over inheritance. Sadly, you're using anonymous structs, but given that you're clearly trying to json marshal them, you're better of defining them as types:
type name struct {
Name string `json:"name"`
}
type desc struct {
Description string `json:"description"`
}
You can initialize them in the same way as you're currently doing, but instead of struct{<fields>}{init}, you'll just write
a := name{"foo"}
b := desc{"Description"}
You can then combine them in any way you like by writing:
c := struct {
name
description
}{a, b}
One quirk (that might trip you up at first) you have to get used to when composing types like this is how you initialize the members. Say you decide to create a type that combines the other two structs:
type foo struct {
name
description
}
You cannot initialize it like this:
o := foo{"Name value", "description value"}
Go will complain about you using type string as type name. You'll have to write something like this:
o := foo{
name{"Name value"},
description{Description: "Description val"},//optional with field names
}
An in-line composite built using existing objects (cf c := struct{}{a, b}) does this already.
Depending on what you're trying to do, it sometimes is easier to write something like this:
func (s *MyCompositeType) CopyName(n name) {
s.Name = n.Name
//copy other fields
}
It makes life easier when you're nesting composite types several levels deep.
fmt.Sprintf("{\"name\":%q,\"description\":%q}", a.Name, b.Description)? Some things do require some coding...