handler

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package handler contains all handlers for serving POST requests. The payload should have at least one key: message. And it contains the log entry for writing. If a "type" for the entry is not provided, it falls back to "info". If the "timestamp" is not provided, it uses the current time it receives the payload.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoWriter is returned when no write is provided.
	ErrNoWriter = errors.New("no writers specified")

	// ErrNoLogger is returned when no logger specified.
	ErrNoLogger = errors.New("no logger specified")

	// ErrNilLogger is returned when nil logger specified.
	ErrNilLogger = errors.New("nil logger specified")

	// ErrDuplicateWriter is returned on duplicated writers.
	ErrDuplicateWriter = errors.New("duplicated writer")

	// ErrWritingEntry is for when there is a problem with writing the entry.
	ErrWritingEntry = errors.New("writing the entry")

	// ErrEmptyObject is retuned when the payload is an empty object.
	ErrEmptyObject = errors.New("empty object")

	// ErrGettingReader is returned when the reader factory cannot return an
	// appropriate reader for the entry.
	ErrGettingReader = errors.New("getting reader")

	// ErrGettingMap is returned when the payload does not contain a map.
	ErrGettingMap = errors.New("getting map")

	// ErrCorruptedJSON is returned the payload is corrupted.
	ErrCorruptedJSON = errors.New("corrupted json")

	// ErrNoOptions is returned when no option is provided.
	ErrNoOptions = errors.New("no option provided")
)

Functions

func WithLogger added in v0.0.3

func WithLogger(logger internal.FieldLogger) func(*Service) error

WithLogger will return an error if the logger is nil

func WithWriters added in v0.0.3

func WithWriters(ws ...io.Writer) func(*Service) error

WithWriters will return an error if two identical writers are injected.

Types

type Service

type Service struct {
	Writers []io.Writer
	Logger  internal.FieldLogger
}

Service listens to the incoming http requests and decides how to route the payload to be written.

func New added in v0.0.3

func New(opts ...func(*Service) error) (*Service, error)

New returns an error if there is no logger or no writer specified.

func (*Service) RecieveHandler

func (l *Service) RecieveHandler(w http.ResponseWriter, r *http.Request)

RecieveHandler handles the logs coming from the endpoint. It handles all writes in their own goroutine in order to avoid write loss.

Jump to

Keyboard shortcuts

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