-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathformatter.go
35 lines (30 loc) · 1.21 KB
/
formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package shuttle
import (
"io"
"net/http"
)
// SubFormatter formats a complete batch or a subsection of a batch. It may
// split lines in the batch as needed by the destination, making the MsgCount()
// of the formatter different from the MsgCount of the source batch. A
// formatter may emitt more (likely) or less bytes for a given LogLine than the
// actual Logline.
type SubFormatter interface {
MsgCount() int // MsgCount is the number of messages after formatting
io.Reader
}
// HTTPFormatter is the interface that http outlets use to format a HTTP
// request.
type HTTPFormatter interface {
Request() (*http.Request, error) // Request() returns a *http.Request ready to be handled by an outlet
SubFormatter
}
// ResponseHandler needs to handle responses to the requests an outlet submits.
// If a HTTPFormatter is also a ResponseHandler, and the request didn't error,
// an outlet must call HandleResponse with the response to the generated
// request.
type ResponseHandler interface {
HandleResponse(*http.Response) error
}
// NewHTTPFormatterFunc defines the function type for defining creating and
// returning a new Formatter
type NewHTTPFormatterFunc func(b Batch, eData []errData, config *Config) HTTPFormatter