lpx

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2015 License: Apache-2.0 Imports: 3 Imported by: 2

README

lpx - Logplex framing parser for Go

For docs see http://godoc.org/github.com/bmizerany/lpx

Documentation

Overview

Example
package main

import (
	"bufio"
	"github.com/heroku/lumbermill/Godeps/_workspace/src/github.com/bmizerany/lpx"
	"net/http"
)

func main() {
	h := func(w http.ResponseWriter, r *http.Request) {
		lp := lpx.NewReader(bufio.NewReader(r.Body))
		for lp.Next() {
			if string(lp.Header().Name) == "router" {
				decodeMsg(lp.Bytes())
			}
		}
	}
	http.HandleFunc("/drain", h)
	_ = http.ListenAndServe(":8080", nil)
}

func decodeMsg(b []byte) {
	// process b
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesReader

type BytesReader interface {
	io.Reader
	ReadBytes(delim byte) (line []byte, err error)
}
type Header struct {
	PrivalVersion []byte
	Time          []byte
	Hostname      []byte
	Name          []byte
	Procid        []byte
	Msgid         []byte
}

A Header represents a single header in a logplex entry. All fields are popluated.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

A Reader provides sequential access to logplex packages. The Next method advances to the next entry (including the first), and then can be treated as an io.Reader to access the packages payload.

func NewReader

func NewReader(r BytesReader) *Reader

NewReader creates a new Reader reading from r.

func (*Reader) Bytes

func (r *Reader) Bytes() []byte

Bytes returns the message body.

func (*Reader) Err

func (r *Reader) Err() error

Err returns the first non-EOF error that was encountered by the Reader.

func (*Reader) Header

func (r *Reader) Header() *Header

Header returns the current entries decoded header.

func (*Reader) Next

func (r *Reader) Next() bool

Next advances to the next entry in the stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL