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

Difference between var Foo structure and type Foo structure

王林
Release: 2024-02-06 09:15:04
forward
568 people have browsed it

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"`
    }
Copy after login

and:

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

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template