// addPPDHashToPrinters fetches description, PPD hash, manufacturer, model for // all argument printers, concurrently. // // Returns a new printer slice, because it can shrink due to raw or // mis-configured printers. func (c *CUPS) addDescriptionToPrinters(printers []lib.Printer) []lib.Printer { var wg sync.WaitGroup ch := make(chan *lib.Printer, len(printers)) for i := range printers { if !lib.PrinterIsRaw(printers[i]) { wg.Add(1) go func(p *lib.Printer) { if description, ppdHash, manufacturer, model, err := c.pc.getDescription(p.Name); err == nil { p.Description.Absorb(description) p.CapsHash = ppdHash p.Manufacturer = manufacturer p.Model = model ch <- p } else { glog.Error(err) } wg.Done() }(&printers[i]) } } wg.Wait() close(ch) result := make([]lib.Printer, 0, len(ch)) for printer := range ch { result = append(result, *printer) } return result }
// filterRawPrinters removes raw printers from the slice. func filterRawPrinters(printers []lib.Printer) []lib.Printer { result := make([]lib.Printer, 0, len(printers)) for i := range printers { if !lib.PrinterIsRaw(printers[i]) { result = append(result, printers[i]) } } return result }