Documentation
¶
Overview ¶
Package handler contains bootstrapping logic for the application, and 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 ¶
- Variables
- func Bootstrap(logger internal.FieldLogger, configFile string, port int)
- func Serve(s ServiceInt, logger internal.FieldLogger, stop chan os.Signal, port int) error
- func WithConfWriters(logger internal.FieldLogger, c *config.Setting) func(*Service) error
- func WithTimeout(timeout time.Duration) func(*Service) error
- func WithWriters(ws ...io.Writer) func(*Service) error
- type Service
- type ServiceInt
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoWriter is returned when no write is provided. ErrNoWriter = errors.New("no writers specified") // ErrNilLogger is returned when logger is nil. ErrNilLogger = errors.New("logger cannot be nil") // 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") // ErrGettingReader is returned when the reader factory cannot return an // appropriate reader for the entry. ErrGettingReader = errors.New("getting reader") // 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") )
var ServeFunc func(s ServiceInt, logger internal.FieldLogger, stop chan os.Signal, port int) error
ServeFunc is a function that is run for setting up the handlers.
Functions ¶
func Bootstrap ¶
func Bootstrap(logger internal.FieldLogger, configFile string, port int)
Bootstrap reads the command options and starts the server.
func Serve ¶
func Serve(s ServiceInt, logger internal.FieldLogger, stop chan os.Signal, port int) error
Serve starts a http.Server in a goroutine. It listens to the Interrupt signal and shuts down the server. It returns any errors occurred during the service. In case of graceful shut down, it will nil.
func WithConfWriters ¶
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 ¶
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
// contains filtered or unexported fields
}
Service listens to the incoming http requests and decides how to route the payload to be written.
func (*Service) Handler ¶
func (l *Service) Handler() http.HandlerFunc
func (*Service) RecieveHandler ¶
func (l *Service) RecieveHandler(w http.ResponseWriter, r *http.Request)
RecieveHandler handles the logs coming from the endpoint. It handles the writes in a goroutine in order to avoid write loss. It will log any errors that might occur during writes. It returns a http.StatusBadRequest if the payload is not a valid JSON object or does not contain the required fields.
type ServiceInt ¶
type ServiceInt interface {
Handler() http.HandlerFunc
Timeout() time.Duration
}
ServiceInt is an interface for the handler.Service