Standard library / go/token
go/token.Position
Expanded diagnostic position with byte offset, one-based line and byte column. Expected stdout: '4 2 2\n'.
Formal Syntax & Structure
go syntaxgo
type Position struct { Filename string Offset int Line int Column int}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")) p := f.Position(f.Pos(4)) fmt.Println(p.Offset, p.Line, p.Column)}