add: default from to log parser

This commit is contained in:
Inanc Gumus
2019-08-06 17:15:29 +03:00
parent 9c57aad7d9
commit 450018748b
3 changed files with 8 additions and 5 deletions

View File

@ -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).

View File

@ -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),
}
}

View File

@ -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 {