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 ¶
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") // ErrTimeout is returned when the timeout is zero. ErrTimeout = errors.New("timeout cannot be zero") )
Functions ¶
func WithConfWriters ¶ added in v0.0.5
WithConfWriters uses a config.Setting object to set up the writers. If any errors occurred during writer instantiation, it stops and returns that error.
func WithTimeout ¶ added in v0.0.5
WithTimeout sets the timeout on Service. It returns an error if the timeout is zero.
Types ¶
type Service ¶
type Service struct {
// Writers is a slice of all writers.
Writers []io.Writer
// Logger is used for logging service's behaviours.
Logger internal.FieldLogger
// Timeout for shutting down the http server. Default is 5 seconds.
Timeout time.Duration
}
Service listens to the incoming http requests and decides how to route the payload to be written.
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.
func (*Service) Serve ¶ added in v0.0.5
Serve starts a http.Server in a goroutine. It listens to the Interrupt signal and shuts down the server. It sends back the errors through the errChan channel. In case of graceful shut down, it will send an io.EOF error to the error channel to signal it has been stopped gracefully.