Skip to content

Commit

Permalink
Added limit flag
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
nitishm committed Sep 11, 2019
1 parent 29c31ee commit 25ca2c5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ import (

var (
isIstioProxyLogs bool
limit int
)

func init() {
flag.BoolVar(&isIstioProxyLogs, "use-istio", false, "Enable to use istio-proxy format")
flag.IntVar(&limit, "limit", 0, "Limit number of lines parsed. Set to 0 for unlimited scroll")
}

func main() {
var p *parser.Parser
var enableLimits bool

flag.Parse()

log.Printf("Reading input from STDIN. Use the pipe \"|\" operator to redirect traffic to engarde")
Expand All @@ -30,6 +34,10 @@ func main() {
p = parser.New(parser.EnvoyAccessLogsPattern)
}

if limit > 0 {
enableLimits = true
}

scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
Expand All @@ -43,5 +51,12 @@ func main() {
accessLog.ParseError = err.Error()
}
fmt.Fprintf(os.Stdout, string(bAccessLog))

if enableLimits {
limit = limit - 1
if limit == 0 {
os.Exit(0)
}
}
}
}

0 comments on commit 25ca2c5

Please sign in to comment.