-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (40 loc) · 1.25 KB
/
main.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
48
49
50
package main
import (
"runtime"
"./cli"
"./listingType"
"./productType"
"./resultType"
"./productByManufacturerType"
"fmt"
)
func main() {
runtime.GOMAXPROCS(4)
listingsFilename, productsFilename, outputFilename := cli.ParseCommandLine()
listingChannel := make(chan *listingType.Data, 32)
go listingType.Read(listingsFilename, listingChannel)
productChannel := make(chan *productType.Data, 32)
go productType.Read(productsFilename, productChannel)
manufacturer := productByManufacturerType.New()
for product := range productChannel {
manufacturer.AddProduct(product)
}
manufacturer.AddAlias("hp", "hewlett packard")
manufacturer.AddAlias("konica minolta", "minolta")
manufacturer.AddAlias("konica minolta", "konica")
manufacturer.AddAlias("fujifilm", "fuji")
manufacturer.AddAlias("kodak", "eastman kodak")
matchedChannel := resultType.Write(outputFilename, manufacturer.ResultChannel)
cnt := 0
notfoundCnt := 0
for listing := range listingChannel {
cnt++
if sent := manufacturer.SendListingOnManufacturerChannel(listing); !sent {
notfoundCnt++
}
}
manufacturer.Close()
fmt.Println(cnt, "listings read.")
fmt.Println(notfoundCnt, "listing with unknown manufucturer.")
fmt.Println(<- matchedChannel, "matches written.")
}