Standard library / os
os.UserConfigDir()
Returns the per-user configuration directory, subject to OS and environment. Does not create it. Unix uses XDG_CONFIG_HOME or HOME fallback. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: '/bytemind/config\n'.
Formal Syntax & Structure
go syntaxgo
func UserConfigDir() (string, error)Return Value
(string, error)
Returns the per-user configuration directory, subject to OS and environment.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func must(e error) { if e != nil { panic(e) }}func main() { must(os.Setenv("XDG_CONFIG_HOME", "/bytemind/config")) p, e := os.UserConfigDir() must(e) fmt.Println(p)}