Documentation
¶
Overview ¶
Package xdgdir implements the Free Desktop Base Directory specification for locating directories.
The specification is at http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
Example ¶
package main import ( "fmt" "os" "go4.org/xdgdir" ) func main() { // Print the absolute path of the current user's XDG_CONFIG_DIR. fmt.Println(xdgdir.Config.Path()) // Read a file from $XDG_CONFIG_DIR/myconfig.json. // This will search for a file named "myconfig.json" inside // $XDG_CONFIG_DIR and then each entry inside $XDG_CONFIG_DIRS. // It opens and returns the first file it finds, or returns an error. if f, err := xdgdir.Data.Create("myconfig.json"); err == nil { fmt.Fprintln(f, "Hello, World!") if err := f.Close(); err != nil { fmt.Fprintln(os.Stderr, err) } } else { fmt.Fprintln(os.Stderr, err) } // Write a file to $XDG_DATA_DIR/myapp/foo.txt if f, err := xdgdir.Data.Create("myapp/foo.txt"); err == nil { fmt.Fprintln(f, "Hello, World!") f.Close() } else { fmt.Fprintln(os.Stderr, err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
A Dir is a logical base directory along with additional search directories.
func (Dir) Create ¶
Create creates the named file inside the directory mode 0666 (before umask), truncating it if it already exists. Parent directories of the file will be created with mode 0700.
func (Dir) Open ¶
Open opens the named file inside the directory for reading. If the directory has multiple search paths, each path is checked in order for the file and the first one found is opened.
func (Dir) Path ¶
Path returns the absolute path of the primary directory, or an empty string if there's no suitable directory present. This is the path that should be used for writing files.
func (Dir) SearchPaths ¶
SearchPaths returns the list of paths (in descending order of preference) to search for files.