Skip to content

Instantly share code, notes, and snippets.

@crdrost
Created May 17, 2024 01:27
Show Gist options
  • Save crdrost/ce08b2449d438a2c3b18fe64cad39095 to your computer and use it in GitHub Desktop.
Save crdrost/ce08b2449d438a2c3b18fe64cad39095 to your computer and use it in GitHub Desktop.
package parse_argo
import (
"io"
"regexp"
"github.com/go-logfmt/logfmt"
"github.com/msoap/byline"
)
type ParseArgo struct {
dec *logfmt.Decoder
}
func NewParseArgo(r io.Reader) ParseArgo {
dropLines := byline.NewReader(r).GrepByRegexp(regexp.MustCompile(`^time=`))
return ParseArgo{ dec: logfmt.NewDecoder(dropLines) }
}
func (p ParseArgo) NextLine() map[string]string, error {
var result map[string]string
dec := p.dec
if dec.ScanRecord() {
result = make(map[string]string)
for dec.ScanKeyval() {
result[string(dec.Key())] = string(dec.Value())
}
}
return result, dec.Err()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment