Standard library / go/token
go/token.FileSet.File()
Finds the file that contains a position or returns nil. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
func (s *FileSet) File(p Pos) (f *File)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | Pos | Compact source position in the associated file set. |
Return Value
(f *File)
Finds the file that contains a position or returns nil.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/token")
func main() { s := token.NewFileSet() f := s.AddFile("demo.go", -1, 5) f.SetLinesForContent([]byte("ab\ncd")) fmt.Println(s.File(f.Pos(2)) == f, s.File(token.NoPos) == nil)}