Small helper library to help you locate useful directories based on the following resources:
- https://stackoverflow.com/a/41598938
- https://stackoverflow.com/a/39868933
- https://apple.stackexchange.com/questions/28928/what-is-the-macos-equivalent-to-windows-appdata-folder
go get github.com/zarthus/appdir
API:
GetApplicationDirectory(); // not for linux (presently)
GetUserConfigDirectory();
Example:
package main
import (
"github.com/zarthus/appdir"
"path/filepath"
"os"
)
func main() {
dir, _ := appdir.GetUserConfigDirectory() // TODO error handling
apppath := filepath.Join(dir, "myapp")
_ = os.MkdirAll(apppath, 0750)
_ = os.WriteFile(filepath.Join(apppath, "config.json"), []byte("{\"foo\": true}"), 0644)
// on linux, this would for example create `~/.config/myapp/config.json` with `{"foo": true}`
}