github.com/yandex/pandora@v0.5.32/core/datasource/file.go (about) 1 package datasource 2 3 import ( 4 "io" 5 "os" 6 7 "github.com/spf13/afero" 8 "github.com/yandex/pandora/core" 9 ) 10 11 // TODO(skipor): auto unzip with option to turn this behaviour off. 12 13 type FileConfig struct { 14 Path string `config:"path" validate:"required"` 15 } 16 17 func NewFile(fs afero.Fs, conf FileConfig) core.DataSource { 18 return &fileSource{afero.Afero{Fs: fs}, conf} 19 } 20 21 type fileSource struct { 22 fs afero.Afero 23 conf FileConfig 24 } 25 26 func (s *fileSource) OpenSource() (wc io.ReadCloser, err error) { 27 return s.fs.Open(s.conf.Path) 28 } 29 30 func NewStdin() core.DataSource { 31 return hideCloseFileSource{os.Stdin} 32 } 33 34 type hideCloseFileSource struct{ afero.File } 35 36 func (f hideCloseFileSource) OpenSource() (wc io.ReadCloser, err error) { 37 return f, nil 38 } 39 40 func (f hideCloseFileSource) Close() error { return nil }