Back to course

Channels: Communicating Between Goroutines

Go (Golang) for Cloud-Native Microservices

Don't Share Memory, Share Data

Channels are the pipes that connect concurrent Goroutines. You send values into channels from one Goroutine and receive those values in another.

go ch := make(chan string)

go func() { ch <- "message" // Send }()

msg := <-ch // Receive (blocks until message arrives)

Channels prevent race conditions by design because data ownership is passed between routines.