Documentation ¶
Overview ¶
Package xdg provides functions related to freedesktop.org.
Index ¶
Examples ¶
Constants ¶
const ( // DefaultURLSchemeHandlerProperty is the default URL scheme handler property. DefaultURLSchemeHandlerProperty = "default-url-scheme-handler" // DefaultWebBrowserProperty is the default web browser property. DefaultWebBrowserProperty = "default-web-browser" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseDirectorySpecification ¶
type BaseDirectorySpecification struct { ConfigHome string ConfigDirs []string DataHome string DataDirs []string CacheHome string RuntimeDir string StateHome string }
A BaseDirectorySpecification represents an XDG Base Directory Specification configuration. See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html.
func NewBaseDirectorySpecification ¶
func NewBaseDirectorySpecification() (*BaseDirectorySpecification, error)
NewBaseDirectorySpecification returns a new BaseDirectorySpecification, configured from the user's environment variables.
func NewTestBaseDirectorySpecification ¶
func NewTestBaseDirectorySpecification(homeDir string, getenv GetenvFunc) *BaseDirectorySpecification
NewTestBaseDirectorySpecification returns a new BaseDirectorySpecification using homeDir and the getenv function. getenv can be nil, in which case default values are returned.
func (*BaseDirectorySpecification) OpenConfigFile ¶
func (b *BaseDirectorySpecification) OpenConfigFile(fsys fs.FS, nameComponents ...string) (fs.File, string, error)
OpenConfigFile opens the first configuration file with the given name found, its full path, and any error. If no file can be found, the error will be fs.ErrNotExist.
func (*BaseDirectorySpecification) OpenDataFile ¶
func (b *BaseDirectorySpecification) OpenDataFile(fsys fs.FS, nameComponents ...string) (fs.File, string, error)
OpenDataFile opens the first data file with the given name found, its full path, and any error. If no file can be found, the error will be fs.ErrNotExist.
type GetenvFunc ¶
A GetenvFunc is a function that gets an environment variable, like os.Getenv.
type Setting ¶
A Setting is a setting.
func (Setting) Check ¶
Check checks that value of s is value. See https://portland.freedesktop.org/doc/xdg-settings.html.
Example ¶
package main import ( "fmt" xdg "github.com/twpayne/go-xdg/v6" ) func main() { setting := xdg.Setting{ Property: xdg.DefaultWebBrowserProperty, SubProperty: "", } isGoogleChrome, err := setting.Check("google-chrome.desktop") if err != nil { panic(err) } fmt.Println(isGoogleChrome) }
Output:
func (Setting) Get ¶
Get gets the value of s.
Example ¶
package main import ( "fmt" xdg "github.com/twpayne/go-xdg/v6" ) func main() { setting := xdg.Setting{ Property: xdg.DefaultURLSchemeHandlerProperty, SubProperty: "http", } value, err := setting.Get() if err != nil { panic(err) } fmt.Println(value) }
Output: