February 2018
Intermediate to advanced
340 pages
9h 43m
English
package main import ( "bufio" "context" "fmt" "log" "strings" "golang.org/x/sync/errgroup" ) const data = `line one line two with more words error: This is erroneous line` func main() { log.Printf("Application %s starting.", "Error Detection") scanner := bufio.NewScanner(strings.NewReader(data)) scanner.Split(bufio.ScanLines) // For each line fire a goroutine g, _ := errgroup.WithContext(context.Background()) for scanner.Scan() { row := scanner.Text() g.Go(func() error { return func(s string) error { if strings.Contains(s, "error:") { return fmt.Errorf(s) } return nil }(row) }) } // ...Read now
Unlock full access