better index path configurability (#128)

This commit is contained in:
Michael Quigley 2023-03-06 14:26:11 -05:00
parent 728ae4b7b0
commit 7a1d491b99
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -11,8 +11,8 @@ import (
)
type FileSourceConfig struct {
Path string
DataPath string
Path string
IndexPath string
}
func loadFileSourceConfig(v interface{}, opts *cf.Options) (interface{}, error) {
@ -38,10 +38,9 @@ func (s *fileSource) Start(events chan map[string]interface{}) (join chan struct
}
_ = f.Close()
idxPath := s.cfg.Path + ".idx"
idxF, err := os.OpenFile(idxPath, os.O_CREATE|os.O_RDWR, os.ModePerm)
idxF, err := os.OpenFile(s.indexPath(), os.O_CREATE|os.O_RDWR, os.ModePerm)
if err != nil {
return nil, errors.Wrapf(err, "error opening '%v'", idxPath)
return nil, errors.Wrapf(err, "error opening '%v'", s.indexPath())
}
pos := int64(0)
@ -98,3 +97,11 @@ func (s *fileSource) tail(pos int64, events chan map[string]interface{}, idxF *o
}
}
}
func (s *fileSource) indexPath() string {
if s.cfg.IndexPath == "" {
return s.cfg.Path + ".idx"
} else {
return s.cfg.IndexPath
}
}