1
0
mirror of https://github.com/Luzifer/bind-log-metrics.git synced 2024-09-19 19:42:56 +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 ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"os" "os"
"regexp" "regexp"
@ -62,7 +63,18 @@ func main() {
log.WithError(err).Fatal("Unable to create metrics client") 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() { for scanner.Scan() {
var line = scanner.Text() var line = scanner.Text()