Guest User

Untitled

a guest
Oct 18th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. func (c *Checker) CheckStandardsGoroutineChannel(ctx context.Context, svc *Service, svcChan chan *Service, errChan chan []error) {
  2. // this function still does what CheckStandards does,
  3. // but instead of returning the values,
  4. // it sends the values to channel
  5. svcChan <- svc
  6. errChan <- errorList
  7. }
  8.  
  9. func main() {
  10. ctx := context.Background()
  11.  
  12. kube := &Kubernetes{}
  13. checker := &Checker{}
  14.  
  15. services, _ := kube.AllServices(ctx)
  16.  
  17. // create channel
  18. svcChan := make(chan *Service)
  19. errChan := make(chan []error)
  20.  
  21. for _, svc := range services {
  22. // spawn goroutine
  23. go checker.CheckStandardsGoroutineChannel(ctx, svc, svcChan, errChan)
  24. }
  25.  
  26. var result []*Service
  27. var errorLog [][]error
  28.  
  29. for i := range services {
  30. tmpSvc, tmpErr := <-svcChan, <-errChan
  31. if len(tmpErr) > 0 {
  32. errorLog = append(errorLog, tmpErr)
  33. }
  34. result = append(result, tmpSvc)
  35. }
  36.  
  37. // do the rest as you like
  38. }
Add Comment
Please, Sign In to add comment