© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
A. FreemanPro Gohttps://doi.org/10.1007/978-1-4842-7355-5_10

10. Defining Structs

Adam Freeman1  
(1)
London, UK
 
In this chapter, I describe structs, which is how custom data types are defined in Go. I show you how to define new struct types, describe how to create values from those types, and explain what happens when values are copied. Table 10-1 puts structs in context.
Table 10-1

Putting Structs in Context

Question

Answer

What are they?

Structs are data types, comprised of fields.

Why are they useful?

Structs allow custom data types to be defined.

How are they used?

The type and struct keywords are used to define a type, allowing field names and types to be specified. ...

Get Pro Go: The Complete Guide to Programming Reliable and Efficient Software Using Golang now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.