What does it mean to declare struct with var?

Viewed 268

I found the struct is defined in the source code of a package like this:

var resp struct {
    CreateTodo struct{ ID string }
}

I always define the struct like this:

type resp struct {
    CreateTodo struct{ ID string }
}

I have never seen this. After searching, I only found a doc about it. But there is no explanation of its meaning. So, what's the difference between type xxx struct {} and var xxx struct {}? When and how should I use var xxx struct {}? Thanks.

1 Answers

This declares a variable resp whose type is the (anonymous) struct.

Related