I need to get the string variable from the channel in a switch statement.
go version go1.19.6 linux/amd64 .\test.go:12:12: syntax error: unexpected :=, expecting :
package main
import (
"fmt"
)
func main() {
writeMsgs := make(chan string)
go sendMsgs(writeMsgs)
for {
switch{
case msg := <-writeMsgs:
fmt.Println(msg)
}
}
}
func sendMsgs(writeMsgs chan string) {
for i:=0;i<5;i++ {
writeMsgs<-"Test"
}
close(writeMsgs)
}
I have cross-referenced multiple tutorials and don't see where I am going wrong.