Golang go/token.Position.String function example

package go/token

String returns a string in one of several forms:

  • file:line:column valid position with file name

  • line:column valid position without file name

  • file invalid position with file name

  • - invalid position without file name

Golang go/token.Position.String function usage example

Example 1:

 func loc(fset *token.FileSet, pos token.Pos) string {
 if pos == token.NoPos {
 return ""
 }
 return " at " + fset.Position(pos).String()
 }

Example 2:

 func (p *printer) internalError(msg ...interface{}) {
  if debug {
 fmt.Print(p.pos.String() + ": ")
 fmt.Println(msg...)
 panic("internal error in somefile.go")
  }
 }

Reference :

http://golang.org/pkg/go/token/#Position.String

Advertisement