Any difference between these two declarations?
type Foo = struct {
F string `zoom:"1"`
}
and
type Foo struct {
F string `zoom:"1"`
}
they both compile and seem to work the same.
Any difference between these two declarations?
type Foo = struct {
F string `zoom:"1"`
}
and
type Foo struct {
F string `zoom:"1"`
}
they both compile and seem to work the same.
The 2nd one, it's an example of struct declaration.
type Foo struct {
F string `zoom:"1"`
}
And the 1st one, it is usage example of go1.9 new feature: type aliases.
A new type Foo
is created. It's an alias of an anonymous struct.
type Foo = struct {
F string `zoom:"1"`
}
The type aliases syntax can be used to define a struct. In example above, it's generating an equivalent result like type Foo struct
.
But, the original purpose of type alias is to make an alias from defined type.
In example below, a new type called Bar
is created and it's an alias of Foo
struct.
type Foo struct {
F string `zoom:"1"`
}
type Bar = Foo