dol / configdir

Multi platform library of configuration directories for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

configdir for Golang

Multi platform library of configuration directory for Golang.

This library helps to get regular directories for configuration files or cache files that matches target operationg system's convention.

It assumes the following folders are standard paths of each environment:

Windows: Linux/BSDs: MacOSX:
System level configuration folder %PROGRAMDATA% (C:\\ProgramData) ${XDG_CONFIG_DIRS} (/etc/xdg) /Library/Application Support
User level configuration folder %APPDATA% (C:\\Users\\<User>\\AppData\\Roaming) ${XDG_CONFIG_HOME} (${HOME}/.config) ${HOME}/Library/Application Support
User wide cache folder %LOCALAPPDATA% (C:\\Users\\<User>\\AppData\\Local) ${XDG_CACHE_HOME} (${HOME}/.cache) ${HOME}/Library/Caches

Examples

Getting Configuration

configdir.ConfigDir.QueryFolderContainsFile() searches files in the following order:

  • Local path (if you add the path via LocalPath parameter)
  • User level configuration folder(e.g. $HOME/.config/<vendor-name>/<application-name>/setting.json in Linux)
  • System level configuration folder(e.g. /etc/xdg/<vendor-name>/<application-name>/setting.json in Linux)

configdir.Config provides some convenient methods(ReadFile, WriteFile and so on).

Write Configuration

When storing configuration, get configuration folder by using configdir.ConfigDir.QueryFolders() method.

Getting Cache Folder

It is similar to the above example, but returns cache folder.

Document

https://godoc.org/github.com/shibukawa/configdir

License

MIT

About

Multi platform library of configuration directories for Golang

License:MIT License


Languages

Language:Go 100.0%