-
Notifications
You must be signed in to change notification settings - Fork 17
Feat/filewatcher go example #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ## Requirements | ||
|
|
||
| * Go **1.22+** | ||
| * macOS (uses `fsnotify`, compatible with FSEvents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fsnotify according to their readme is cross platform right? Or atleast can work on linux&mac
| * PDF-only file filtering | ||
| * Detects file lifecycle events: | ||
|
|
||
| * `FILE_ADDED` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work outlining this
I'm curious how file renames are represented. As a FILE_UPDATED? or as a FILE_REMOVED+FILE_ADDED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably ignore the built binary as well
| * Directory not found → Program exits with a descriptive error | ||
| * API failure → Logged; watcher continues running | ||
| * Permission issues → Logged as warnings | ||
| * Non-PDF files → Ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More like it ignores files not suffixed with .pdf ... they may be valid pdf files but you took the suffix detection approach (which is fine for this example tbh)
Alternatively we could have used a detection approach where we try and check the first 5 bytes are %PDF- and that would potentially catch more valid pdfs. However, because we are leaving actual PDF parsing for some upstream component I'd say the suffix approach is fine but we should properly document
| cfg := &Config{} | ||
|
|
||
| flag.StringVar(&cfg.Dir, "dir", "", "Directory to watch") | ||
| flag.StringVar(&cfg.APIURL, "api-url", "", "API endpoint") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP API is not a bad choice tbh but given that we expect the watcher to run on the same system as the future components (atleast for this example), how about a unix domain socket path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is deprecated now given the structure below
|
|
||
| --- | ||
|
|
||
| ## Project Structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file watcher is one piece out of the project... perhaps the entire project should be named something like pdfsearch and the filewatcher is one binary under pdfsearch that pushes events to the indexer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either that or filewatcher, indexer and searcher are things you spin up at once as such
// instantiate some connecting channel between watcher and indexer
go fileWatcher.Watch(connChann)
go indexer.Index(connChann)
go searcher.InitAPI()
Adds a filewatcher CLI that watches a directory for PDF file changes and posts normalized file events to an HTTP API. Includes event debouncing for macOS, structured logging, and a clean, extensible architecture for future processing pipelines to examples directory for go lang