How to Use Directional Channels (chan<- and <-chan) in Go

Use chan<- T for send-only and <-chan T for receive-only channels to restrict data flow direction in Go.

Use chan<- T to declare a send-only channel and <-chan T to declare a receive-only channel, restricting operations to prevent accidental misuse.

// Send-only channel: can only send values
toWorker := make(chan<- int)
toWorker <- 42

// Receive-only channel: can only receive values
fromWorker := make(<-chan int)
result := <-fromWorker

// Bidirectional channel: can send and receive
worker := make(chan int)
worker <- 10
val := <-worker