如何在go中使用os.Name()?

I'm trying to use: https://golang.org/src/os/file.go?s=1472:1577#L35

by importing the "os" package and then running

f, err := os.Open("/tmp/dat3")
check(err)
name := os.Name(f)

I get ./main.go:29: undefined: os.Name

Why? What am I doing wrong.

(Of course I know I have the name of the open file - but I'm curious why, I'm not able to call that function)

Because Name is a special function (method) defined on File struct. Means it takes File type as receiver and can be called using receiver instance (in your case f).

This should work

name := f.Name()

Read more at :

https://tour.golang.org/methods/1

https://gobyexample.com/methods