Channels
package main
import "fmt"
func main() {
// Creating a channel named 'messages' for communication between goroutines
messages := make(chan string)
// Launching a goroutine with an anonymous function to send a message into the channel
go func() {
messages <- "ping" // Sending "ping" into the 'messages' channel
}()
// Receiving the message from the channel and storing it in the variable 'msg'
msg := <-messages
// Printing the received message
fmt.Println(msg)
}Output
Last updated