go-ltsv: github.com/Songmu/go-ltsv Index | Examples | Files

package ltsv

import "github.com/Songmu/go-ltsv"

Index

Examples

Package Files

decode.go encode.go

func Marshal Uses

func Marshal(v interface{}) ([]byte, error)

Marshal returns the LTSV encoding of v

func Unmarshal Uses

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the LTSV-encoded data and stores the result in the value pointed to by v.

Code:

package main

import (
    "net"
    "time"

    "github.com/Songmu/go-ltsv"
    "github.com/kr/pretty"
)

type log struct {
    Time    logTime
    Host    net.IP
    Req     string
    Status  int
    Size    int
    UA      string
    ReqTime float64
    AppTime *float64
    VHost   string
}

const timeFormat = "2006-01-02T15:04:05Z07:00"

type logTime struct {
    time.Time
}

func (lt *logTime) UnmarshalText(t []byte) error {
    ti, err := time.ParseInLocation(timeFormat, string(t), time.UTC)
    if err != nil {
        return err
    }
    lt.Time = ti
    return nil
}

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)
    pretty.Println(l)
}

type MarshalError Uses

type MarshalError map[string]error

MarshalError is an error type for Marshal()

func (MarshalError) Error Uses

func (m MarshalError) Error() string

func (MarshalError) OfField Uses

func (m MarshalError) OfField(name string) error

OfField returns the error correspoinding to a given field

type MarshalTypeError Uses

type MarshalTypeError struct {
    Value string
    Type  reflect.Type
}

An MarshalTypeError describes a LTSV value that was not appropriate for a value of a specific Go type.

func (*MarshalTypeError) Error Uses

func (e *MarshalTypeError) Error() string

type UnmarshalError Uses

type UnmarshalError map[string]error

UnmarshalError is an error type for Unmarshal()

func (UnmarshalError) Error Uses

func (m UnmarshalError) Error() string

func (UnmarshalError) OfField Uses

func (m UnmarshalError) OfField(name string) error

OfField returns the error correspoinding to a given field

type UnmarshalTypeError Uses

type UnmarshalTypeError struct {
    Value string
    Type  reflect.Type
}

An UnmarshalTypeError describes a LTSV value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error Uses

func (e *UnmarshalTypeError) Error() string

Package ltsv imports 5 packages (graph). Updated 2016-07-21. Refresh now. Tools for package owners.