1
0
Fork 0
mirror of https://github.com/Luzifer/bind-log-metrics.git synced 2024-11-08 16:00:04 +00:00

Allow specifying input file

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-01-25 20:09:01 +01:00
parent e4322c2f02
commit 0c248599e0
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

14
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"bufio"
"fmt"
"io"
"os"
"regexp"
@ -62,7 +63,18 @@ func main() {
log.WithError(err).Fatal("Unable to create metrics client")
}
scanner := bufio.NewScanner(os.Stdin)
var input io.Reader = os.Stdin
if len(rconfig.Args()) > 1 {
f, err := os.Open(rconfig.Args()[1])
if err != nil {
log.WithError(err).Fatal("Unable to open input file")
}
defer f.Close()
input = f
}
scanner := bufio.NewScanner(input)
for scanner.Scan() {
var line = scanner.Text()