Browse Source

Added UserCache{File,Dir} and renamed User{File,Dir} to UserConfig{File,Dir}.

master
Sander Schobers 1 year ago
parent
commit
a6415a1d60
  1. 33
      io.go

33
io.go

@ -132,8 +132,31 @@ func NewTempDir(prefix string) (*Dir, error) {
return &Dir{path}, nil
}
// UserDir gives back the user configuration directory with given name.
func UserDir(name string) (string, error) {
// UserCacheDir gives back the user configuration directory with given name.
func UserCacheDir(name string) (string, error) {
config, err := os.UserCacheDir()
if err != nil {
return "", err
}
dir := filepath.Join(config, name)
err = os.MkdirAll(dir, 0777)
if err != nil {
return "", err
}
return dir, nil
}
// UserCacheFile gives back the path to the file with the specified name and the directory named app.
func UserCacheFile(app, name string) (string, error) {
dir, err := UserCacheDir(app)
if err != nil {
return "", err
}
return filepath.Join(dir, name), nil
}
// UserConfigDir gives back the user configuration directory with given name.
func UserConfigDir(name string) (string, error) {
config, err := os.UserConfigDir()
if err != nil {
return "", err
@ -146,9 +169,9 @@ func UserDir(name string) (string, error) {
return dir, nil
}
// UserFile gives back the path to the file with the specified name and the directory named app.
func UserFile(app, name string) (string, error) {
dir, err := UserDir(app)
// UserConfigFile gives back the path to the file with the specified name and the directory named app.
func UserConfigFile(app, name string) (string, error) {
dir, err := UserConfigDir(app)
if err != nil {
return "", err
}

Loading…
Cancel
Save