/
sources.go
31 lines (24 loc) · 860 Bytes
/
sources.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
package harvester
import (
"io"
"os"
)
type LogSource interface {
io.ReadCloser
Name() string
}
type FileSource interface {
LogSource
Stat() (os.FileInfo, error)
Continuable() bool // can we continue processing after EOF?
}
// restrict file to minimal interface of FileSource to prevent possible casts
// to additional interfaces supported by underlying file
type pipeSource struct{ file *os.File }
func (p pipeSource) Read(b []byte) (int, error) { return p.file.Read(b) }
func (p pipeSource) Close() error { return p.file.Close() }
func (p pipeSource) Name() string { return p.file.Name() }
func (p pipeSource) Stat() (os.FileInfo, error) { return p.file.Stat() }
func (p pipeSource) Continuable() bool { return false }
type fileSource struct{ *os.File }
func (fileSource) Continuable() bool { return true }