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 pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro