-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_provider.go
53 lines (45 loc) · 887 Bytes
/
url_provider.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
51
52
53
package edgarwebcrawler
import (
"bufio"
"log"
"os"
"sync"
)
type SubmissionUrlProvider interface {
Start(urlC chan<- string) error
Stop()
}
type TextFileSubmissionsUrlProvider struct {
filePath string
quit chan bool
}
func NewUrlProvider(filePath string) *TextFileSubmissionsUrlProvider {
return &TextFileSubmissionsUrlProvider{
filePath: filePath,
quit: make(chan bool),
}
}
func (t *TextFileSubmissionsUrlProvider) Start(urlC chan<- string) error {
file, err := os.Open(t.filePath)
if err != nil {
return err
}
waitgroup := sync.WaitGroup{}
waitgroup.Add(1)
go func() {
fileReader := bufio.NewReader(file)
for {
submission, err := ReadLine(fileReader)
if err != nil {
log.Println(err)
break
}
urlC <- submission
}
waitgroup.Done()
}()
return nil
}
func (t *TextFileSubmissionsUrlProvider) Stop() {
t.quit <- true
}