Giter Site home page Giter Site logo

go-userdirs's Introduction

go-userdirs

godoc reference

This is a small Go library for building suitable paths for storing and locating application-specific, user-specific configuration files, data files, and cache files.

It has first-class support for the following operating systems:

The library also supports AIX, DragonFlyBSD, FreeBSD, NetBSD, OpenBSD, and Solaris by following the XDG specification, treating them like Linux.


Concepts

The library is based on similar principles as the XDG specification, namely:

  • There are one or more directories to search for configuration files, one of which is preferred and used for creating new configuration files.
  • There are one or more directories to search for data files, one of which is preferred and used for creating new data files.
  • There is exactly one cache directory, which can be used for transient files that the application is able to recreate if lost.

The exact locations of these directories will depend on operating system and system configuration, but we assume that there is at least one directory of each type. Sometimes the same directory will appear in more than one role.

The distinction between configuration and data files is subtle, but a rule of thumb is to think about whether it would make sense to keep a particular file under version control if a user were motivated to keep configuration in a version control system. Configuration files tend to be relatively small, ideally in text-based formats that humans could easily read and edit. Data files might be larger, and may be opaque binary files.

Some configuration and data directories may roam between multiple machines, so applications should either use host-agnostic file formats there or use other mechanisms to partition files to avoid collisions, such as using a separate subdirectory for each supported OS.

The cache directory is commonly (though not guaranteed to be) a local directory that does not roam between machines. Its contents could be lost at any time, so applications should store here only files that can be easily recreated when needed.

Helpers

The entry-point for the package is userdirs.ForApp, which uses some given identifying information to construct application-specific subdirectory paths under the operating-system-specific base directories.

The Dirs object it returns has some helper methods for scanning across the various directories to find files:

  • FindConfigFiles and FindDataFiles scan over their respective directory lists and find all instances of a particular constant sub-path, like a specific configuration file name.
  • GlobConfigFiles and GlobDataFiles are similar, but apply a glob pattern to each directory that could potentially return multiple results. This could be useful to collect up all files with with a particular file extension across all selected directories, for example.

Contributing

The featureset of this library is considered "done" and so it's unlikely that any new capabilities will be added. However, bug fixes are much appreciated.

One enhancement area that is open is support for new operating systems. However, once support for an operating system is added the set of directories returned for it is largely frozen to ensure that dependent applications can continue to find files they previously created, so there is a bar for adding a new operating system: there must be a standards document published by the operating system vendor that defines the set of rules that this library would then follow when running on that operating system, with confidence that the standards are long-lived and not likely to need breaking changes in future.

If you'd like to contribute support for a new operating system, please open an issue to discuss it. Note also that we currently use Travis-CI for testing, and so we're constrained for what platforms we can run unit tests on. An operating system without native Travis-CI support would need to be particularly compelling for it to be accepted, since we would need to find some other way to automatically test it.

Any pull requests are assumed to be submitted under the same MIT License as the library is already shared under, as described in LICENSE.

go-userdirs's People

Contributors

apparentlymart avatar ajacoutot avatar

Stargazers

Andreas Gajdosik avatar ik5 avatar weebney avatar AJ Beck avatar

Watchers

James Cloos avatar  avatar

Forkers

ajacoutot v1gnesh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.