main is the entry point for all Go programs.
()
| 45 | |
| 46 | // main is the entry point for all Go programs. |
| 47 | func main() { |
| 48 | var wg sync.WaitGroup |
| 49 | wg.Add(maxGoroutines) |
| 50 | |
| 51 | // Create the pool to manage our connections. |
| 52 | p, err := pool.New(createConnection, pooledResources) |
| 53 | if err != nil { |
| 54 | log.Println(err) |
| 55 | } |
| 56 | |
| 57 | // Perform queries using connections from the pool. |
| 58 | for query := 0; query < maxGoroutines; query++ { |
| 59 | // Each goroutine needs its own copy of the query |
| 60 | // value else they will all be sharing the same query |
| 61 | // variable. |
| 62 | go func(q int) { |
| 63 | performQueries(q, p) |
| 64 | wg.Done() |
| 65 | }(query) |
| 66 | } |
| 67 | |
| 68 | // Wait for the goroutines to finish. |
| 69 | wg.Wait() |
| 70 | |
| 71 | // Close the pool. |
| 72 | log.Println("Shutdown Program.") |
| 73 | p.Close() |
| 74 | } |
| 75 | |
| 76 | // performQueries tests the resource pool of connections. |
| 77 | func performQueries(query int, p *pool.Pool) { |
nothing calls this directly
no test coverage detected