Documentation
¶
Overview ¶
Package reader contains logic for reading from a provider. Any types that implements the DataReader interface can be used in this system. The Result should provide a byte slice that is JSON unmarshallable, otherwise the data will be rejected.
Important Notes ¶
When the token's context is cancelled, the reader should finish its job and return. The Time should be set when the data is read from the endpoint, otherwise it will lose its meaning. The engine will issue jobs based on the Interval, which is set in the configuration file.
Index ¶
- Variables
- func WithBackoff(backoff int) func(Constructor) error
- func WithEndpoint(endpoint string) func(Constructor) error
- func WithInterval(interval time.Duration) func(Constructor) error
- func WithLogger(log internal.FieldLogger) func(Constructor) error
- func WithMapper(mapper datatype.Mapper) func(Constructor) error
- func WithName(name string) func(Constructor) error
- func WithTimeout(timeout time.Duration) func(Constructor) error
- func WithTypeName(typeName string) func(Constructor) error
- type Constructor
- type DataReader
- type ErrEndpointNotAvailable
- type ErrInvalidEndpoint
- type ErrLowBackoffValue
- type ErrLowInterval
- type ErrLowTimeout
- type Result
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyName = fmt.Errorf("name cannot be empty") ErrEmptyEndpoint = fmt.Errorf("endpoint cannot be empty") ErrEmptyTypeName = fmt.Errorf("type_name cannot be empty") ErrBackoffExceeded = fmt.Errorf("endpoint gone too long") ErrPingNotCalled = fmt.Errorf("the caller forgot to ask me pinging") )
ErrEmptyName is the error when the package name is empty. ErrEmptyEndpoint is the error when the given endpoint is empty. ErrEmptyTypeName is the error when the type_name is an empty string. ErrBackoffExceeded is the error when the endpoint's absence has exceeded the backoff value. It is not strictly an error, it is however a pointer to an error in the past. ErrPingNotCalled is the error if the caller calls the record without pinging.
Functions ¶
func WithBackoff ¶ added in v0.9.0
func WithBackoff(backoff int) func(Constructor) error
WithBackoff sets the backoff of the reader
func WithEndpoint ¶ added in v0.9.0
func WithEndpoint(endpoint string) func(Constructor) error
WithEndpoint sets the endpoint of the reader
func WithInterval ¶ added in v0.9.0
func WithInterval(interval time.Duration) func(Constructor) error
WithInterval sets the interval of the reader
func WithLogger ¶ added in v0.9.0
func WithLogger(log internal.FieldLogger) func(Constructor) error
WithLogger sets the log of the reader
func WithMapper ¶ added in v0.9.0
func WithMapper(mapper datatype.Mapper) func(Constructor) error
WithMapper sets the mapper of the reader
func WithName ¶ added in v0.9.0
func WithName(name string) func(Constructor) error
WithName sets the name of the reader
func WithTimeout ¶ added in v0.9.0
func WithTimeout(timeout time.Duration) func(Constructor) error
WithTimeout sets the timeout of the reader
func WithTypeName ¶ added in v0.9.0
func WithTypeName(typeName string) func(Constructor) error
WithTypeName sets the typeName of the reader
Types ¶
type Constructor ¶ added in v0.8.1
type Constructor interface { SetLogger(logger internal.FieldLogger) SetName(name string) SetTypeName(typeName string) SetEndpoint(endpoint string) SetMapper(mapper datatype.Mapper) SetInterval(interval time.Duration) SetTimeout(timeout time.Duration) SetBackoff(backoff int) }
Constructor is a Reader object that will accept configurations.
type DataReader ¶ added in v0.1.2
type DataReader interface { Name() string Ping() error Read(*token.Context) (*Result, error) Mapper() datatype.Mapper TypeName() string Timeout() time.Duration Interval() time.Duration }
DataReader receives job requests to read from the target. It returns an error if the data cannot be read or the connection is refused.
Notes ¶
Readers should not intercept the engine's decision on the TypeName, unless they have a valid reason. Name() should return the representation string for this reader. Ping() should ping the endpoint and return nil if was successful. The Engine will not launch the reader if the ping result is an error. When the context is timed-out or cancelled, Read() should return. Mapper() should return an instance of the datatype mapper. Engine uses this object to present the data to recorders. TypeName() is usually the application name and is set by the user in the configuration file.
Example (Read) ¶
This example shows the reader hits the endpoint when the Read method is called.
package main import ( "context" "fmt" "io" "net/http" "net/http/httptest" reader "github.com/arsham/expipe/reader/testing" "github.com/arsham/expipe/token" ) func main() { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, `{"the key": "is the value!"}`) })) defer ts.Close() red := reader.GetReader(ts.URL) // this is a mocked version, but the example's principals stays the same. err := red.Ping() fmt.Println("Ping errors:", err) job := token.New(context.Background()) res, err := red.Read(job) // Issuing a job if err == nil { // Lets check the errors fmt.Println("No errors reported") } fmt.Println("Result is:", string(res.Content)) }
Output: Ping errors: <nil> No errors reported Result is: {"the key": "is the value!"}
type ErrEndpointNotAvailable ¶ added in v0.5.0
ErrEndpointNotAvailable is the error when the endpoint is not available.
func (ErrEndpointNotAvailable) Error ¶ added in v0.5.0
func (e ErrEndpointNotAvailable) Error() string
type ErrInvalidEndpoint ¶ added in v0.5.0
type ErrInvalidEndpoint string
ErrInvalidEndpoint is the error when the endpoint is not a valid url.
func (ErrInvalidEndpoint) Error ¶ added in v0.5.0
func (e ErrInvalidEndpoint) Error() string
type ErrLowBackoffValue ¶ added in v0.6.0
type ErrLowBackoffValue int64
ErrLowBackoffValue is the error when the backoff value is lower than 5
func (ErrLowBackoffValue) Error ¶ added in v0.6.0
func (e ErrLowBackoffValue) Error() string
type ErrLowInterval ¶ added in v0.8.1
ErrLowInterval is the error when the interval is zero
func (ErrLowInterval) Error ¶ added in v0.8.1
func (e ErrLowInterval) Error() string
type ErrLowTimeout ¶ added in v0.8.1
ErrLowTimeout is the error when the interval is zero
func (ErrLowTimeout) Error ¶ added in v0.8.1
func (e ErrLowTimeout) Error() string
type Result ¶ added in v0.7.0
type Result struct { // ID is the job ID given by the Engine. // This ID should not be changed until it is recorded. ID token.ID //Time is set after the request was successfully read. Time time.Time // TypeName comes from the configuration, but the Engine might decide // to change it. TypeName string // Content should be json unmarshallable, otherwise the job will be dropped. Content []byte // Mapper is the mapper set in the reader. Mapper datatype.Mapper }
Result is constructed every time a new data is fetched.
Directories
¶
Path | Synopsis |
---|---|
Package expvar contains logic to read from an expvar provide.
|
Package expvar contains logic to read from an expvar provide. |
Package self contains codes for recording expipe's own metrics.
|
Package self contains codes for recording expipe's own metrics. |
Package testing is a test suit for readers.
|
Package testing is a test suit for readers. |