Golang go/token.FileSet.Iterate function examples
package go/token
Iterate calls f (inner function) for the files in the file set in the order they were added until f returns false.
Golang go/token.FileSet.Iterate function usage examples
Example 1:
func printStats(d time.Duration) {
fileCount := 0
lineCount := 0
fset.Iterate(func(f *token.File) bool {
fileCount++
lineCount += f.LineCount()
return true
})
fmt.Printf(
"%s (%d files, %d lines, %d lines/s)\n",
d, fileCount, lineCount, int64(float64(lineCount)/d.Seconds()),
)
}
Example 2:
innerfunc := func(f *token.File) bool {
files = append(files, f.Name())
return true
}
func scopeFiles(prog *loader.Program) []string {
files := make([]string, 0)
prog.Fset.Iterate(innerfunc) // <-- here
sort.Strings(files)
return files
}
References :
Advertisement
Something interesting
Tutorials
+12k Golang : Decompress zlib file example
+15.3k nginx: [emerg] unknown directive "ssl"
+14.4k Golang : Parsing or breaking down URL
+10.6k Golang : Simple File Server
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+28.7k Golang : Detect (OS) Operating System
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+8.7k Golang : Find duplicate files with filepath.Walk
+6.3k Apt-get to install and uninstall Golang
+9.7k Golang : Format strings to SEO friendly URL example
+18.6k Golang : Get download file size