Let's break down your question (as originally asked, since you posted on meta when the original version was live).
How do I embed a channel in a struct in go? Why the inconsistency
between the map syntax:
var m map[string]int
and channel,
var m chan int
First, as has been pointed out, this is two questions, not one. Yes, I know StackOverflow imposes a character limit that you view as "arbitrary". Like most restrictions on the site, it exists for a reason. In this case, because very very few quality questions can be asked in so few characters.
But let's assume you'd been able to post what you had wanted to:
How do I embed a channel in a struct in go?
This is not a good question. It is on-topic, and perfectly clear what you want to do, but it shows exactly zero effort on your part before asking - and you don't have to be an expert in Go to figure that out. Given that you have several other questions in the Go
tag which could have been answered by just looking up the syntax, this is a poor trend. Not showing effort is guaranteed to earn you downvotes.
So, what could you have done to demonstrate that you had put in effort? Assuming the question isn't actually about syntax (because you should be able to answer syntax questions with your own research), then you would have tried the obvious syntax and found that it failed in some way. (I'm not familiar with Go, so the below is my best attempt at getting the idea across.)
How do I embed a channel in a struct in go? I tried the obvious way:
type MyType struct {
*Channel
}
But when I do this I get an error:
func (x chan int) m2() {}
invalid receiver type chan int (chan int is an unnamed type)
This is a question which is on-topic, answerable, and shows that you've put in some effort. Had you posted this originally, you would not have received so many downvotes and you could have moved on, happy with VonC's excellent answer.