Difference between var Foo struct and type Foo struct

59 Views Asked by At

I have hard time to understand what is the diffrence between:

var requestPayLoad struct {
        Email string `json:"email"`
        Password string `json:"string"`
    }

and:

type jwtUSer struct {
    ID        int    `json:"id"`
    FirstName string `json:"first_name"`
    LastName  string `json:"last_name"`
}

one is type and one is a var.

1

There are 1 best solutions below

0
mkopriva On BEST ANSWER
  • var v T creates a variable, binds the identifier v to it, gives it the type T, and then initializes it to the zero-value of T.
  • type t T binds the identifier t to type T.

In both cases type T may be a named or an unnamed (anonymous) type.