Standard library / go/token

go/token.File.LineStart()

Returns the position of a physical one-based line start; invalid line numbers panic. Expected stdout: '3\n'.

Formal Syntax & Structure

go syntaxgo
func (f *File) LineStart(line int) Pos

Parameters & Attributes

NameTypeDescription
lineintOne-based source line number.

Return Value

Pos

Returns the position of a physical one-based line start; invalid line numbers panic.

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"))  fmt.Println(f.Offset(f.LineStart(2)))}
Go Reference