package main import ( "bufio" "fmt" "os" "time" ) var messages = make(chan Message) type Message struct { Count int Text string } func pinger() { for { msg := <-messages fmt.Println(msg) msg.Count++ msg.Text = "Ping!" messages <- msg time.Sleep(1000 * time.Millisecond) } } func ponger() { for { msg := <- messages fmt.Println(msg) msg.Count++ msg.Text = "Pong!" messages <- msg time.Sleep(1000 * time.Millisecond) } } func main() { go pinger() go ponger() messages <- Message{0, ""} bufio.NewReader(os.Stdin).ReadBytes('\n') }