-
Notifications
You must be signed in to change notification settings - Fork 1
/
tickets.go
47 lines (43 loc) · 1.25 KB
/
tickets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package multasgt
import (
"net/http"
"sync"
)
// Tickets represents all collected tickets
type Tickets struct {
Tickets []Ticket
M sync.Mutex
}
func getTickets(wg *sync.WaitGroup,
plateType, plateNumber string,
tckts *Tickets,
checker TicketChecker) {
defer wg.Done()
var tickets []Ticket
tickets, _ = checker.Check(plateType, plateNumber)
tckts.M.Lock()
tckts.Tickets = append(tckts.Tickets, tickets...)
tckts.M.Unlock()
}
// GetAllTickets retrieves tickets from all entities.
func GetAllTickets(plateType, plateNumber string, c *http.Client) ([]Ticket, error) {
var wg sync.WaitGroup
wg.Add(7)
var tickets Tickets
// Emetra
go getTickets(&wg, plateType, plateNumber, &tickets, &Emetra{Client: c})
// Mixco
go getTickets(&wg, plateType, plateNumber, &tickets, &Emixtra{Client: c})
// SCP
go getTickets(&wg, plateType, plateNumber, &tickets, &SCP{Client: c})
// Fraijanes
go getTickets(&wg, plateType, plateNumber, &tickets, &Fraijanes{Client: c})
// Antigua
go getTickets(&wg, plateType, plateNumber, &tickets, &Antigua{Client: c})
// PNC
go getTickets(&wg, plateType, plateNumber, &tickets, &PNC{Client: c})
// VillaNueva
go getTickets(&wg, plateType, plateNumber, &tickets, &VillaNueva{Client: c})
wg.Wait()
return tickets.Tickets, nil
}