Standard library / path/filepath
path/filepath.EvalSymlinks()
Resolves symbolic links in a pathname and cleans the result; resolution may fail and is not a race-free containment check. Example uses a disposable temporary workspace. Expected stdout: 'a.txt\n'.
Formal Syntax & Structure
go syntaxgo
func EvalSymlinks(path string) (string, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Pathname interpreted according to this package. |
Return Value
(string, error)
Resolves symbolic links in a pathname and cleans the result; resolution may fail and is not a race-free containment check.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "path/filepath")
func check(e error) { if e != nil { panic(e) }}func seed() { check(os.WriteFile("a.txt", []byte("abc"), 0600)) }func workspace() func() { root, e := os.MkdirTemp("", "bytemind-go-") check(e) old, e := os.Getwd() check(e) check(os.Chdir(root)) return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()() seed() check(os.Symlink("a.txt", "alias")) p, e := filepath.EvalSymlinks("alias") check(e) fmt.Println(p)}