Home >Backend Development >Golang >Difference between var Foo structure and type Foo structure

Difference between var Foo structure and type Foo structure

王林
王林forward
2024-02-06 09:15:04575browse

var Foo 结构和 type Foo 结构之间的区别

Question content

I have a hard time understanding the difference between the two:

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 a type and the other is a variable.


correct answer


  • var v T Create a variable, bind the identifier v to it, give it T, and then It is initialized to a zero value of T.
  • type t T Binds the identifier T to the type T.

In both cases, the T type can be a named or unnamed (anonymous) type.

The above is the detailed content of Difference between var Foo structure and type Foo structure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete