Lin Du
Lin Du

Reputation: 102207

What does it mean to declare struct with var?

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.

Upvotes: 3

Views: 1392

Answers (1)

Henry
Henry

Reputation: 43728

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

Upvotes: 3

Related Questions