Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 14 of 60 · Go

Channels: Communication Between Goroutines

Duration: 20 minutes

Channels

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Channels are typed conduits that allow goroutines to communicate safely.

ch := make(chan int) // unbuffered channel

go func() { ch <- 42 }() // send
val := <-ch // receive
fmt.Println(val) // 42

Buffered channels

buf := make(chan string, 3) // capacity 3
buf <- "a"
buf <- "b"
fmt.Println(<-buf) // a

Closing channels

close(buf)
for v := range buf { fmt.Println(v) }

Select statement (multiplexing)

select {
case v := <-ch1:
    fmt.Println("from ch1", v)
case ch2 <- 99:
    fmt.Println("sent to ch2")
default:
    fmt.Println("no activity")
}

Info

Reading from a closed channel yields the zero value without panic. Sending on a closed channel panics.

Previous: Concurrency Primer: GoroutinesNext: Concurrency Patterns: Worker Pools