The worker pool design pattern is one where you dispatch long-running Goroutines as workers. These workers can process a variety of work either using multiple channels, or by using a stateful request structure that specifies the type, as described in the preceding recipe. This recipe will create stateful workers and demonstrate how to coordinate and spin up multiple workers who are all handling requests concurrently on the same channel. These workers will be crypto workers, as in a web authentication application. Their purpose will be to hash plaintext strings using the bcrypt package and compare a text password against a hash.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter10/pooland navigate to it.
- Run the following command:
$ go mod...