Golang go/scanner.ErrorList type examples

package go/scanner

ErrorList is a list of *Errors. The zero value for an ErrorList is an empty ErrorList ready to use.

Golang go/scanner.ErrorList type usage examples

Example 1:

 switch err := err.(type) {
 case types.Error:
 posn := a.prog.Fset.Position(err.Pos)
  errors[posn] = append(errors[posn], err.Msg)
 case scanner.ErrorList:
 for _, e := range err {
 errors[e.Pos] = append(errors[e.Pos], e.Msg)
  }

Example 2:

 func report(err error) {
 scanner.PrintError(os.Stderr, err)
 if list, ok := err.(scanner.ErrorList); ok {
 errorCount += len(list)
  return
 }
 errorCount++
 }

Reference :

http://golang.org/pkg/go/scanner/#ErrorList

Advertisement