/
files.go
62 lines (50 loc) · 1.85 KB
/
files.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package input
import (
"github.com/Jeffail/benthos/v3/internal/docs"
"github.com/Jeffail/benthos/v3/lib/input/reader"
"github.com/Jeffail/benthos/v3/lib/log"
"github.com/Jeffail/benthos/v3/lib/metrics"
"github.com/Jeffail/benthos/v3/lib/types"
)
//------------------------------------------------------------------------------
func init() {
Constructors[TypeFiles] = TypeSpec{
constructor: fromSimpleConstructor(NewFiles),
Status: docs.StatusDeprecated,
Summary: `
Reads files from a path, where each discrete file will be consumed as a single
message.`,
Description: `
The path can either point to a single file (resulting in only a single message)
or a directory, in which case the directory will be walked and each file found
will become a message.
## Alternatives
The behaviour of this input is now covered by the ` + "[`file` input](/docs/components/inputs/file)" + `.
### Metadata
This input adds the following metadata fields to each message:
` + "``` text" + `
- path
` + "```" + `
You can access these metadata fields using
[function interpolation](/docs/configuration/interpolation#metadata).`,
Categories: []Category{
CategoryLocal,
},
FieldSpecs: docs.FieldSpecs{
docs.FieldCommon("path", "A path to either a directory or a file."),
docs.FieldCommon("delete_files", "Whether to delete files once they are consumed."),
},
}
}
//------------------------------------------------------------------------------
// NewFiles creates a new Files input type.
func NewFiles(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
var f reader.Async
var err error
if f, err = reader.NewFiles(conf.Files); err != nil {
return nil, err
}
f = reader.NewAsyncPreserver(f)
return NewAsyncReader(TypeFiles, true, f, log, stats)
}
//------------------------------------------------------------------------------