Skip to content
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

How can I import this project in my code? does it have documents and examples? #20

Open
ghost opened this issue May 1, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented May 1, 2022

How can I import this project in my code? does it have documents and examples?

@ozeidan
Copy link
Owner

ozeidan commented May 1, 2022

Hi @aswallz, could you elaborate how you want to use this package? Do you want to search for files from you code?

This program is not designed to be used from code. You could still do that by doing something similar as the file cmd/server/main.go:

fileChangeChan := make(chan fanotify.FileChange, 100)
requestChan := make(chan request.Request)
go fanotify.Listen(fileChangeChan) // listen to file changes on the system
go database.Start(fileChangeChan, requestChan) // start the database, this also creates an initial index of the whole file system
go request.ListenAndServe(requestChan) // set up a server that listens for requests. 

you wouldn't set up the server (the last line). instead you can construct Requests yourself and send them through the requestChan channel and listen for the results on the ResponseChannel field of the Request which you constructed. You might want to write a wrapper for that.

Ideally though we would refactor this whole thing. database should be a struct of a databaser(?) interface which defines functions to report file changes, to query the database and to create the initial index (maybe the latter should be somewhere else). Then you would be able to simply create a database struct and call functions on it to query. Then the whole channel stuff would build on top of that, so we we'd have a cleaner separation of concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant