seniorGolang

Understanding the empty struct `struct{}`.

Updated Apr 28, 2026

Short answer

An empty struct occupies strictly zero bytes of memory. It is used for signaling, sets, and method grouping.

Deep explanation

Because it consumes 0 bytes, creating a map[string]struct{} acts as a highly memory-efficient HashSet in Go. Furthermore, a channel of empty structs chan struct{} is the idiomatic way to send signals between goroutines without transferring any actual data.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Golang interview questions

View all →