Syntax

Go Define a Struct Syntax

In Go, define a struct: groups related fields — type User struct { Name string Age int }

Quick Answer

Syntax
type User struct { Name string Age int }
GoSyntax

Define a Struct

Code example
type User struct { Name string Age int }

Groups related fields.

Learn More

How to define a struct in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Define a Struct Syntax

Use type User struct { Name string Age int }.

Related Syntax References

Frequently asked questions

What is the Go syntax for define a struct?

Use this pattern: type User struct { Name string Age int }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify