wojteninho / scanner Goto Github PK
View Code? Open in Web Editor NEWConvenient and versatile library to iterate through files
License: MIT License
Convenient and versatile library to iterate through files
License: MIT License
Say we want to filter first 100 files from a particular directory. I would love to do it as easy as:
s := NewBuilder().
Files().
In("/my/photos").
Limit(100)
MustBuild()
for item := range MustScan(s.Scan(context.TODO())) {
...
}
Behind the scenes, it should be the new Scanner implementation called LimitScanner
which is not a self-sufficient scanner, but act as a wrapper above the concrete scanner.
basicScanner := NewBasicScanner(WithDir("/my/photos"))
limitScanner := NewLimitScanner(basicScanner, 100)
To get familiar with the idea of wrappers check out available wrappers implementations.
Happy to see PR with this feature :-)
What I have in my mind is to have an easy way to filter out files by modification date.
Say for instance we want to filter out files modified since yesterday:
yesterday := time.Now().AddDate(0, 0, -1)
s := NewBuilder().
Files().
In("/my/photos").
Modified(After(yesterday))
MustBuild()
for item := range MustScan(s.Scan(context.TODO())) {
...
}
Another example is:
yesterday := time.Now().AddDate(0, 0, -1)
s := NewBuilder().
Files().
In("/my/photos").
Modified(Before(yesterday))
MustBuild()
One more could be the between two dates:
twoDaysAgo := time.Now().AddDate(0, 0, -2)
yesterday := time.Now().AddDate(0, 0, -1)
s := NewBuilder().
Files().
In("/my/photos").
Modified(Between(twoDaysAgo, yesterday))
MustBuild()
Behind the scenes it should be the new implementation of Filter interface, and in the builder calling Modified(...)
we should add one more filter.
Check how we eventually combine multiple filters here. Filters comes so far from calls to either Files()
or Directories()
or Match(...)
.
Happy to discuss further ๐ ๐
My use case recently was to iterate through a set of pre-known files and directories. It would be handy to have:
filesScanner := MustScanner(NewFilesScanner(WithFiles("first.go", "second.go")))
dirScanner := MustScanner(NewBasicScanner(WithDirectory("/your/directory/to/scan")))
multiScanner := NewMultiScanner(filesScanner, dirScanner)
FilesScanner
should act as a adapter basically to give a way to iterate through fixed set of files following the same interface as the other concrete implementations of Scanner interface.
We are all developers, we don't like to write documentation. But every package is as good as its documentation... According to the Go Report missing go doc is a weakness of the package.
Happy to see an improvement in this area ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.