Golang go/token.FileSet.File function examples
package go/token
File returns the file that contains the position p(1st parameter). If no such file is found (for instance for p == NoPos), the result is nil.
Golang go/token.FileSet.File function usage examples
Example 1:
func FindFileAst(fset *token.FileSet, file *token.File, fileAsts []*ast.File) *ast.File {
for _, fileAst := range fileAsts {
if fset.File(fileAst.Package) == file {
return fileAst
}
}
return nil
}
Example 2:
for file, pos := range offsets {
f := fset.File(Pos(pos))
if f.Name() != file {
t.Errorf("got %q at position %d, want %q", f.Name(), pos, file)
}
}
References :
Advertisement
Something interesting
Tutorials
+6.2k Golang : Get missing location after unmarshal binary and gob decode time.
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+20.2k Golang : Count number of digits from given integer value
+7k Golang : How to call function inside template with template.FuncMap
+11.8k Golang : Verify Linux user password again before executing a program example
+8.9k Golang : Sort lines of text example
+7.8k Golang : Reverse a string with unicode
+9k Golang : Inject/embed Javascript before sending out to browser example
+8.5k Golang : How to check if input string is a word?
+10.6k Golang : Simple File Server
+7.3k Golang : Calculate how many weeks left to go in a given year