optimize: logparser v5
This commit is contained in:
@ -18,9 +18,13 @@ func main() {
|
||||
// pipe.FilterBy(pipe.DomainExtFilter("com", "io")),
|
||||
// pipe.GroupBy(pipe.DomainGrouper),
|
||||
// )
|
||||
p, err := fromFile(os.Args[1])
|
||||
|
||||
if err = p.Run(); err != nil {
|
||||
p, err := fromFile(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if err := p.Run(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,12 @@ func NewJSONLog(r io.Reader) *JSON {
|
||||
func (j *JSON) Each(yield func(Record) error) error {
|
||||
defer readClose(j.reader)
|
||||
|
||||
// Use the same record for unmarshaling.
|
||||
var r Record
|
||||
|
||||
dec := json.NewDecoder(j.reader)
|
||||
|
||||
for {
|
||||
var r Record
|
||||
|
||||
err := dec.Decode(&r)
|
||||
if err == io.EOF {
|
||||
break
|
||||
|
@ -20,8 +20,8 @@ type Record struct {
|
||||
record
|
||||
}
|
||||
|
||||
// String returns a string field. Panics when the field doesn't exist.
|
||||
func (r Record) String(field string) string {
|
||||
// Str returns a string field. Panics when the field doesn't exist.
|
||||
func (r Record) Str(field string) string {
|
||||
return r.mustGet(field, reflect.String).String()
|
||||
}
|
||||
|
||||
|
@ -26,16 +26,17 @@ func NewTextLog(r io.Reader) *TextLog {
|
||||
func (p *TextLog) Each(yield func(Record) error) error {
|
||||
defer readClose(p.reader)
|
||||
|
||||
// Use the same record for unmarshaling.
|
||||
var r Record
|
||||
|
||||
in := bufio.NewScanner(p.reader)
|
||||
|
||||
for in.Scan() {
|
||||
r := new(Record)
|
||||
|
||||
if err := r.UnmarshalText(in.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := yield(*r); err != nil {
|
||||
if err := yield(r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user