Standard library / go/token
go/token.FileSet.Iterate()
Visits files in registration order until callback returns false. Expected stdout: 'demo.go\n'.
Formal Syntax & Structure
go syntaxgo
func (s *FileSet) Iterate(f func(*File) bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| f | func(*File) bool | Input to the operation as described above. |
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")) s.AddFile("other.go", -1, 1) s.Iterate(func(x *token.File) bool { fmt.Println(x.Name()); return false })}