refactor: logparser v5 to pkgs

This commit is contained in:
Inanc Gumus
2019-08-28 23:46:42 +03:00
parent 4629b59ef2
commit 81b4246973
26 changed files with 601 additions and 458 deletions

39
logparser/v5/filepipe.go Normal file
View File

@ -0,0 +1,39 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"os"
"strings"
"github.com/inancgumus/learngo/logparser/v5/pipe"
)
// fromFile generates a default pipeline.
// Detects the correct parser by the file extension.
// Uses a TextReport and groups by domain.
func fromFile(path string) (*pipe.Pipeline, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
var src pipe.Iterator
switch {
case strings.HasSuffix(path, ".txt"):
src = pipe.NewTextLog(f)
case strings.HasSuffix(path, ".jsonl"):
src = pipe.NewJSONLog(f)
}
return pipe.New(
src,
pipe.NewTextReport(os.Stdout),
pipe.GroupBy(pipe.DomainGrouper),
), nil
}