pinger

package
v1.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePingerLog

func CreatePingerLog(logFilePath string, reinitializeLog bool) error

CreatePingerLog creates the log file used by Pinger and Notifier

func GetEmptySitesMock

func GetEmptySitesMock(db *sql.DB) (database.Sites, error)

GetEmptySitesMock is a mock of the SQL query to get the sites for pinging In this case the method returns an empty list of sites.

func GetLogContent

func GetLogContent() (string, error)

GetLogContent reads the results of the log file for verification.

func GetSites

func GetSites(db *sql.DB) (database.Sites, error)

GetSites provides the implementation of the SitesGetter type for runtime usage.

func GetSitesContentMock added in v1.3.0

func GetSitesContentMock(db *sql.DB) (database.Sites, error)

GetSitesContentMock is a mock of the SQL query to get the sites for testing content checks.

func GetSitesErrorMock

func GetSitesErrorMock(db *sql.DB) (database.Sites, error)

GetSitesErrorMock is a mock of the SQL query to get the sites for pinging In this case it returns an error when getting the sites.

func GetSitesMock

func GetSitesMock(db *sql.DB) (database.Sites, error)

GetSitesMock is a mock of the SQL query to get the sites for pinging

func RequestURL

func RequestURL(url string, timeout int) (string, int, time.Duration, error)

RequestURL provides the implementation of the URLRequester type for runtime usage.

func RequestURLBadInternetAccessMock

func RequestURLBadInternetAccessMock(url string, timeout int) (string, int, time.Duration, error)

RequestURLBadInternetAccessMock mocks the condition where the outgoing Internet connection is down.

func RequestURLContentMock added in v1.3.0

func RequestURLContentMock(url string, timeout int) (string, int, time.Duration, error)

RequestURLContentMock is a mock of the URL requests for checking content.

func RequestURLMock

func RequestURLMock(url string, timeout int) (string, int, time.Duration, error)

RequestURLMock is a mock of the URL request that pings the site.

func ResetHitCount added in v1.3.0

func ResetHitCount()

ResetHitCount sets the hitcount back to 0 for the tests.

Types

type InternetAccessError

type InternetAccessError struct {
	// contains filtered or unexported fields
}

InternetAccessError defines errors where the Internet is inaccessible from the server.

func (InternetAccessError) Error

func (e InternetAccessError) Error() string

type Pinger

type Pinger struct {
	Sites      database.Sites
	DB         *sql.DB
	RequestURL URLRequester
	SendEmail  notifier.EmailSender
	SendSms    notifier.SmsSender
	// contains filtered or unexported fields
}

Pinger does the HTTP pinging of the sites that are retrieved from the DB.

func NewPinger

func NewPinger(db *sql.DB, getSites SitesGetter, requestURL URLRequester,
	sendEmail notifier.EmailSender, sendSms notifier.SmsSender) *Pinger

NewPinger returns a new Pinger object

func (*Pinger) Start

func (p *Pinger) Start()

Start begins the Pinger service to start pinging

func (*Pinger) Stop

func (p *Pinger) Stop()

Stop stops the Pinger service by sending stop to all pingers and waits until all are stopped via the waitgroup.

func (*Pinger) UpdateSiteSettings

func (p *Pinger) UpdateSiteSettings() error

UpdateSiteSettings stops the pinger, regets the sites for changes in settings, and restarts the pinger. There could potentially be race conditions if multiple web controllers were trying to update it so a mutex is used to protect it.

type SitesGetter

type SitesGetter func(db *sql.DB) (database.Sites, error)

SitesGetter defines a function to get the sites from DB or mock.

type URLRequester

type URLRequester func(url string, timeout int) (string, int, time.Duration, error)

URLRequester defines a function to get thre response and error from http or mock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL