Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func (c *Checker) CheckStandardsGoroutineChannel(ctx context.Context, svc *Service, svcChan chan *Service, errChan chan []error) {
- // this function still does what CheckStandards does,
- // but instead of returning the values,
- // it sends the values to channel
- svcChan <- svc
- errChan <- errorList
- }
- func main() {
- ctx := context.Background()
- kube := &Kubernetes{}
- checker := &Checker{}
- services, _ := kube.AllServices(ctx)
- // create channel
- svcChan := make(chan *Service)
- errChan := make(chan []error)
- for _, svc := range services {
- // spawn goroutine
- go checker.CheckStandardsGoroutineChannel(ctx, svc, svcChan, errChan)
- }
- var result []*Service
- var errorLog [][]error
- for i := range services {
- tmpSvc, tmpErr := <-svcChan, <-errChan
- if len(tmpErr) > 0 {
- errorLog = append(errorLog, tmpErr)
- }
- result = append(result, tmpSvc)
- }
- // do the rest as you like
- }
Add Comment
Please, Sign In to add comment