forked from jpillora/overseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher.go
35 lines (29 loc) · 862 Bytes
/
fetcher.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
package fetcher
import "io"
type Interface interface {
//Init should perform validation on fields. For
//example, ensure the appropriate URLs or keys
//are defined or ensure there is connectivity
//to the appropriate web service.
Init() error
//Fetch should check if there is an updated
//binary to fetch, and then stream it back the
//form of an io.Reader. If io.Reader is nil,
//then it is assumed there are no updates. Fetch
//will be run repeatly and forever. It is up the
//implementation to throttle the fetch frequency.
Fetch() (io.Reader, error)
}
//Converts a fetch function into interface
func Func(fn func() (io.Reader, error)) Interface {
return &fetcher{fn}
}
type fetcher struct {
fn func() (io.Reader, error)
}
func (f fetcher) Init() error {
return nil //skip
}
func (f fetcher) Fetch() (io.Reader, error) {
return f.fn()
}