Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUnrecognizedHTTPMethod means that the http method is not recognized ErrUnrecognizedHTTPMethod = errors.New("unrecognized http method") // ErrURLNoScheme means that the url has no http:// or https:// ErrURLNoScheme = errors.New("url does not have a scheme") // ErrInvalidFrequency means that the polling frequency is invalid, i.e. // if it could not be parsed by time.ParseDuration ErrInvalidFrequency = errors.New("invalid polling frequency") // ErrUnsupportedFrequency means that the polling frequency is lower // than five second ErrUnsupportedFrequency = errors.New("frequency cannot be lower than five second") // ErrInvalidRandRange is thrown when the range could not be parsed by // time.ParseDuration or is greater or equal than frequency ErrInvalidRandRange = errors.New("invalid range") )
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
HandlerFunc represents a function that will handle the response returned by the polling.
type Page ¶
type Page struct {
// ID is a short name that will be used by the logs to recognize when
// operations are performed on this page.
ID *string `yaml:"id,omitempty"`
// URL to poll
URL string `yaml:"url"`
// Method of the request, e.g.: GET
Method *string `yaml:"method,omitempty"`
// Headers to send with the request
Headers map[string]string `yaml:"headers,omitempty"`
// UserAgentOptions contains options about the
// user agent
*UserAgentOptions `yaml:"userAgentOptions,omitempty"`
// PollOptions contains options about polling
*PollOptions `yaml:"pollOptions,omitempty"`
// FollowRedirect specifies whether to follow redirects or not.
// Default is false
FollowRedirect bool `yaml:"followRedirect,omitempty"`
}
Page to poll
type PollOptions ¶
type PollOptions struct {
// Frequency of polling in seconds
Frequency int `yaml:"frequency"`
// Randomize specifies whether the next poll should be at a random time or
// at a fixed time
RandomFrequency bool `yaml:"randomFrequency"`
// OffsetRange specifies the range for choosing the next random time.
// For example, if Frequency is 30 and OffsetRange is 10, then each next
// poll will be performed at a random time in the [20, 40] seconds range,
// i.e. 27 seconds.
OffsetRange *int `yaml:"offsetRange,omitempty"`
}
PollOptions contains options about polling
type Poller ¶
type Poller interface {
// Start polling
Start(ctx context.Context, now bool)
// SetHandlerFunc sets the function that will be called when a poll has
// finished
SetHandlerFunc(HandlerFunc)
// GetID returns the ID of this poller. If the `Page` struct provided
// to `New` contained a non-empty `ID`, then this returns the same ID as
// the one contained in there, otherwise it returns a randomly generated
// one.
GetID() string
}
Poller is in charge of polling a website and providing results to a function that will handle the result
type UserAgentOptions ¶
type UserAgentOptions struct {
// UserAgents is a list of user agents that should be used for this page
UserAgents []string `yaml:"userAgents,omitempty"`
// RandomUA specifies whether the user agent for the next request should
// be chosen randomly or should be rotated. This has no effect if
// UserAgents is empty or only has one element. Leave this false if you
// have few user agents.
RandomUA bool `yaml:"randomUA"`
}
UserAgentOptions contains options about the user agent
Click to show internal directories.
Click to hide internal directories.