add: default from to log parser
This commit is contained in:
		| @@ -9,15 +9,12 @@ package main | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	defer recoverErr() | ||||
|  | ||||
| 	_, err := newReport(). | ||||
| 		from(textReader(os.Stdin)). | ||||
| 		to(textWriter(os.Stdout)). | ||||
| 		// filterBy(orgDomainsFilter). | ||||
| 		filterBy(notUsing(domainExtFilter("com", "io"))). | ||||
| 		groupBy(domainGrouper). | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package main | ||||
|  | ||||
| import "os" | ||||
|  | ||||
| type ( | ||||
| 	inputFunc  func() ([]result, error) | ||||
| 	outputFunc func([]result) error | ||||
| @@ -15,6 +17,8 @@ type report struct { | ||||
| func newReport() *report { | ||||
| 	return &report{ | ||||
| 		filter: noopFilter, | ||||
| 		input:  textReader(os.Stdin), | ||||
| 		output: textWriter(os.Stdout), | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -27,16 +27,18 @@ func parseText(in *bufio.Scanner) ([]result, error) { | ||||
| 		lines   int | ||||
| 	) | ||||
|  | ||||
| 	results = make([]result, 0, 5000000) | ||||
|  | ||||
| 	for in.Scan() { | ||||
| 		lines++ | ||||
|  | ||||
| 		result, err := parseFields(strings.Fields(in.Text())) | ||||
| 		res, err := parseFields(strings.Fields(in.Text())) | ||||
| 		if err != nil { | ||||
| 			// TODO: custom error type for line information | ||||
| 			return nil, fmt.Errorf("line %d: %v", lines, err) | ||||
| 		} | ||||
|  | ||||
| 		results = append(results, result) | ||||
| 		results = append(results, res) | ||||
| 	} | ||||
|  | ||||
| 	if err := in.Err(); err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user