external

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DockerProvider

type DockerProvider struct {
	TimeOut time.Duration
}

DockerProvider is a status provider that uses docker

func (*DockerProvider) Status

func (d *DockerProvider) Status(req Request) (*Response, error)

Status the url looks like: docker:///var/run/docker.sock or docker://1.2.3.4:2375 optionally the url can contain a query param "required" with a comma separated list of required container names i.e. docker:///var/run/docker.sock?containers=foo,bar

type HTTPProvider

type HTTPProvider struct {
	http.Client
}

HTTPProvider is an external service that checks the status of a HTTP endpoint

func (*HTTPProvider) Status

func (h *HTTPProvider) Status(req Request) (*Response, error)

Status returns the status of the external service via HTTP GET

type MongoProvider

type MongoProvider struct {
	TimeOut time.Duration
}

MongoProvider is a status provider that uses mongo

func (*MongoProvider) Status

func (m *MongoProvider) Status(req Request) (*Response, error)

Status returns status of mongo, checks if connection established and ping is ok

type Providers

type Providers struct {
	HTTP   StatusProvider
	Mongo  StatusProvider
	Docker StatusProvider
}

Providers is a list of StatusProvider

type Request

type Request struct {
	Name string
	URL  string
}

Request is a name and request to external service

type Response

type Response struct {
	Name         string                 `json:"name"`
	StatusCode   int                    `json:"status_code"`
	ResponseTime int64                  `json:"response_time"` // milliseconds
	Body         map[string]interface{} `json:"body,omitempty"`
}

Response contains extended service information

type Service

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

Service wraps multiple StatusProvider and multiplex their Status() calls

func NewService

func NewService(providers Providers, concurrency int, reqs ...string) *Service

NewService creates new external service supporting multiple providers reqs are requests to external services presented as pairs of name and url, i.e. health:http://localhost:8080/health

func (*Service) Status

func (s *Service) Status() []Response

Status returns extended service information, runs concurrently

type StatusProvider

type StatusProvider interface {
	Status(req Request) (*Response, error)
}

StatusProvider is an interface for getting status from external services

type StatusProviderMock

type StatusProviderMock struct {
	// StatusFunc mocks the Status method.
	StatusFunc func(req Request) (*Response, error)
	// contains filtered or unexported fields
}

StatusProviderMock is a mock implementation of StatusProvider.

func TestSomethingThatUsesStatusProvider(t *testing.T) {

	// make and configure a mocked StatusProvider
	mockedStatusProvider := &StatusProviderMock{
		StatusFunc: func(req Request) (*Response, error) {
			panic("mock out the Status method")
		},
	}

	// use mockedStatusProvider in code that requires StatusProvider
	// and then make assertions.

}

func (*StatusProviderMock) Status

func (mock *StatusProviderMock) Status(req Request) (*Response, error)

Status calls StatusFunc.

func (*StatusProviderMock) StatusCalls

func (mock *StatusProviderMock) StatusCalls() []struct {
	Req Request
}

StatusCalls gets all the calls that were made to Status. Check the length with:

len(mockedStatusProvider.StatusCalls())

Jump to

Keyboard shortcuts

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