-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetcher.go
36 lines (30 loc) · 934 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
36
package fetcher
import "io"
// Interface defines the required fetcher functions
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 repeatedly and forever. It is up the
//implementation to throttle the fetch frequency.
Fetch() (io.Reader, error)
}
// Func converts a fetch function into the fetcher 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()
}