Added UserCache{File,Dir} and renamed User{File,Dir} to UserConfig{File,Dir}.
This commit is contained in:
parent
5e4afbe038
commit
a6415a1d60
33
io.go
33
io.go
@ -132,8 +132,31 @@ func NewTempDir(prefix string) (*Dir, error) {
|
|||||||
return &Dir{path}, nil
|
return &Dir{path}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserDir gives back the user configuration directory with given name.
|
// UserCacheDir gives back the user configuration directory with given name.
|
||||||
func UserDir(name string) (string, error) {
|
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()
|
config, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -146,9 +169,9 @@ func UserDir(name string) (string, error) {
|
|||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserFile gives back the path to the file with the specified name and the directory named app.
|
// UserConfigFile gives back the path to the file with the specified name and the directory named app.
|
||||||
func UserFile(app, name string) (string, error) {
|
func UserConfigFile(app, name string) (string, error) {
|
||||||
dir, err := UserDir(app)
|
dir, err := UserConfigDir(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user