LTSV library to map ltsv to struct.
import (
"net"
"github.com/Songmu/go-ltsv"
)
type log struct {
Host net.IP
Req string
Status int
Size int
UA string
ReqTime float64
AppTime *float64
VHost string
}
func main() {
ltsvLog := "time:2016-07-13T00:00:04+09:00\t" +
"host:192.0.2.1\t" +
"req:POST /api/v0/tsdb HTTP/1.1\t" +
"status:200\t" +
"size:36\t" +
"ua:ua:mackerel-agent/0.31.2 (Revision 775fad2)\t" +
"reqtime:0.087\t" +
"vhost:mackerel.io"
l := &log{}
ltsv.Unmarshal([]byte(ltsvLog), l)
...
}
LTSV parser and encoder for Go with reflection
% go get github.com/Songmu/go-ltsv