Golang go/scanner.PrintError() function examples

package go/scanner

PrintError is a utility function that prints a list of errors to w(1st parameter), one error per line, if the err parameter is an ErrorList. Otherwise it prints the err(2nd parameter) string.

Golang go/scanner.PrintError() function usage examples

Example 1:

 if p, err := processFile(filename); err != nil {
 log.Printf("\t%s\n\n", filename)
 scanner.PrintError(os.Stderr, err) // <-- here
 exitCode = 1
 }

Example 2:

 if len(list) != 9 {
 t.Errorf("found %d sorted errors, expected 9", len(list))
 PrintError(os.Stderr, list)
 }

Reference :

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

Advertisement