Skip to Content
Head First Go
book

Head First Go

by Jay McGavren
April 2019
Beginner
556 pages
14h 21m
English
O'Reilly Media, Inc.
Content preview from Head First Go

Chapter 8. building storage: Structs

image

Sometimes you need to store more than one type of data.

We learned about slices, which store a list of values. Then we learned about maps, which map a list of keys to a list of values. But both of these data structures can only hold values of one type. Sometimes, you need to group together values of several types. Think of billing receipts, where you have to mix item names (strings) with quantities (integers). Or student records, where you have to mix student names (strings) with grade point averages (floating-point numbers). You can’t mix value types in slices or maps. But you can if you use another type called a struct. We’ll learn all about structs in this chapter!

Slices and maps hold values of ONE type

Gopher Fancy is a new magazine devoted to lovable rodents. They’re currently working on a system to keep track of their subscriber base.

image
image

It’s true: arrays, slices, and maps are no help if you need to mix values of different types. They can only be set up to hold values of a single type. But Go does have a way to solve this problem...

Structs are built out of values of MANY types

A struct (short for “structure”) is a value that is ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Git

Head First Git

Raju Gandhi
Learning Go

Learning Go

Jon Bodner
Head First Software Architecture

Head First Software Architecture

Raju Gandhi, Mark Richards, Neal Ford
Head First Design Patterns, 2nd Edition

Head First Design Patterns, 2nd Edition

Eric Freeman, Elisabeth Robson

Publisher Resources

ISBN: 9781491969540Errata Page