Golang go/token.File.Line function examples
package go/token
Line returns the line number for the given file position p(1st parameter); p must be a Pos value in that file or NoPos.
Golang go/token.File.Line function usage examples
Example 1:
if file := x.fset.File(p); file != nil {
if base := file.Base(); base <= m[1] && m[1] <= base+file.Size() {
// match [m[0], m[1]) is within the file boundaries
list[found].filename = file.Name()
list[found].line = file.Line(p) // <--- here
found++
}
}
Example 2:
var p *parser
if p.file.Line(p.pos) == p.file.Line(prev) {
// do something
}
Reference :
Advertisement
Something interesting
Tutorials
+10.3k Golang : How to check if a website is served via HTTPS
+37.5k Upload multiple files with Go
+12.2k Golang : calculate elapsed run time
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+19.7k Golang : Archive directory with tar and gzip
+15.2k Golang : Accurate and reliable decimal calculations
+17.1k Golang : Capture stdout of a child process and act according to the result
+13.1k Golang : How to get a user home directory path?
+8.8k Golang : Get final balance from bit coin address example
+7.3k Golang : alternative to os.Exit() function
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+6.2k Golang & Javascript : How to save cropped image to file on server