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

xdg: Add the hability to initialize a new BaseDir with different FS behind #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xescugc
Copy link

@xescugc xescugc commented May 18, 2022

This allows to not only use the machine FS but any other supported by afero.Fs in this case.

This is a PoC PR as I want to be sure this is a correct way to do it in your opinion, for me it looks clean and requires no changes for people already using this lib.

The idea behind is to have the BaseDirectories be able to be initialized with an afero.Fs and make it public so anyone could choose what to do. By default the baseDir is initialized with afero.NewOsFs() which uses the stdlib of GO for os so it works as it worked before.

Another solution would be to have a global variable with the FS to use but I really hate to use global variables for this things, and having a way to initialize different xdg with different FS makes it easy to use IMO.

We could also make the variable BaseDir public or add a public function to change that value instead of having the New but I had the same feeling of global things not beeing that useful and easy to use/understand.

If this changes where to be on the right way there are a few things still to be done:

  • Change all the test to use afero.NewMemMapFs which is an in-memory implementation of a FS, quite useful for testing.
  • Update the documentation
  • Potentially update the examples?

Whenever you have time take a look and if it's ok I'll continue with the things I mention to finish or any other thing you may want or suggestion to change :).

Closes #35

…ehind

This allows to not only use the machine FS but any other supported by afero.Fs in this case
@xescugc
Copy link
Author

xescugc commented Aug 6, 2022

I've added a Reload to the main struct and initialize it as it was needed in order to not have an empty set when initializing it, this also emulates the main Reaload and also holds a copy of the global varibles internally in case they may differe (if Reload is called)

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

Successfully merging this pull request may close these issues.

Custom file system support?
1 participant