On Saturday, 12 September 2020 17:04:19 UTC+1, mb0 wrote: > > a global map is the way to go, however writing an reading the map from > multiple go routines will fail (in your case different handle calls for > connections) because the map data structure is not safe for concurrent use > and must be coordinated. the way it is usually solved is by adding another > sync.Mutex (mutually exclusive) variable to ensure only one go routine at a > has access to the map. > > <https://godoc.org/sync#Mutex> >
Another very common pattern is to have a separate goroutine for each connection, and then the goroutines communicate using channels. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1cc5595e-d2ef-4dda-ab27-ce2052752393o%40googlegroups.com.