https://github.com/emersion/go-appdir
Go package to get application directories such as config and cache
https://github.com/emersion/go-appdir
Last synced: about 1 year ago
JSON representation
Go package to get application directories such as config and cache
- Host: GitHub
- URL: https://github.com/emersion/go-appdir
- Owner: emersion
- License: mit
- Created: 2020-11-20T12:44:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-14T09:20:44.000Z (over 5 years ago)
- Last Synced: 2025-04-10T12:16:15.813Z (about 1 year ago)
- Language: Go
- Size: 19.5 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-appdir
[](https://godoc.org/github.com/emersion/go-appdir)
Go package to get application directories such as config and cache.
Platform | Windows | [Linux/BSDs] | [macOS]
-------- | ------- | ------------------------------------------------------------------------------------------ | -----
User-specific config | `%APPDATA%` (`C:\Users\%USERNAME%\AppData\Roaming`) | `$XDG_CONFIG_HOME` (`$HOME/.config`) | `$HOME/Library/Application Support`
User-specific cache | `%LOCALAPPDATA%` (`C:\Users\%USERNAME%\AppData\Local`) | `$XDG_CACHE_HOME` (`$HOME/.cache`) | `$HOME/Library/Caches`
User-specific data | `%LOCALAPPDATA%` (`C:\Users\%USERNAME%\AppData\Local`) | `$XDG_DATA_HOME` (`$HOME/.local/share`) | `$HOME/Library/Application Support`
User-specific logs | `%LOCALAPPDATA%` (`C:\Users\%USERNAME%\AppData\Local`) | `$XDG_CACHE_HOME//logs` | `$HOME/Library/Logs`
[Linux/BSDs]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
[macOS]: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1
Inspired by [`configdir`](https://github.com/shibukawa/configdir).
## Usage
```go
package main
import (
"os"
"path/filepath"
"github.com/emersion/go-appdir"
)
func main() {
// Get directories for our app
dirs := appdir.New("my-awesome-app")
// Get user-specific config dir
p := dirs.UserConfig()
// Create our app config dir
if err := os.MkdirAll(p, 0755); err != nil {
panic(err)
}
// Now we can use it
f, err := os.Create(filepath.Join(p, "config-file"))
if err != nil {
panic(err)
}
defer f.Close()
f.Write([]byte("<3"))
}
```
## License
MIT