service

package
v0.0.0-...-ab02cca Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BuildTime represents the time in which the service was built
	BuildTime string
	// GitCommit represents the commit (SHA-1) hash of the service that is running
	GitCommit string
	// Version represents the version of the service that is running
	Version string
)

Functions

This section is empty.

Types

type ExternalServiceList

type ExternalServiceList struct {
	HealthCheck bool
	Init        Initialiser
}

ExternalServiceList holds the initialiser and initialisation state of external services.

func NewServiceList

func NewServiceList(initialiser Initialiser) *ExternalServiceList

NewServiceList creates a new service list with the provided initialiser

func (*ExternalServiceList) GetDownloadServiceAPIClient

func (e *ExternalServiceList) GetDownloadServiceAPIClient(cfg *config.Config) (storage.DownloadServiceAPIClient, error)

func (*ExternalServiceList) GetHTTPServer

func (e *ExternalServiceList) GetHTTPServer(bindAddr string, router http.Handler) HTTPServer

GetHTTPServer creates an http server

func (*ExternalServiceList) GetHealthCheck

func (e *ExternalServiceList) GetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)

GetHealthCheck creates a healthcheck with versionInfo and sets the HealthCheck flag to true

func (*ExternalServiceList) GetHealthClient

func (e *ExternalServiceList) GetHealthClient(name, url string) *health.Client

GetHealthClient returns a healthclient for the provided URL

func (*ExternalServiceList) GetInteractivesAPIClient

func (e *ExternalServiceList) GetInteractivesAPIClient(apiRouter *health.Client) (routes.InteractivesAPIClient, error)

GetInteractivesAPIClient creates an interactives api client and sets the InteractivesApi flag to true

func (*ExternalServiceList) GetStorageProvider

GetStorageProvider returns storage provider depending on config: localfs, s3, static files (dp-download-service)

type HTTPServer

type HTTPServer interface {
	ListenAndServe() error
	Shutdown(ctx context.Context) error
}

HTTPServer defines the required methods from the HTTP server

type HealthChecker

type HealthChecker interface {
	AddCheck(name string, checker healthcheck.Checker) (err error)
	Handler(w http.ResponseWriter, req *http.Request)
	Start(ctx context.Context)
	Stop()
}

HealthChecker defines the required methods from Healthcheck

type Init

type Init struct{}

Init implements the Initialiser interface to initialise dependencies

func (*Init) DoGetDownloadServiceAPIClient

func (e *Init) DoGetDownloadServiceAPIClient(cfg *config.Config) (storage.DownloadServiceAPIClient, error)

func (*Init) DoGetHTTPServer

func (e *Init) DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer

DoGetHTTPServer creates an HTTP Server with the provided bind address and router

func (*Init) DoGetHealthCheck

func (e *Init) DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)

DoGetHealthCheck creates a healthcheck with versionInfo

func (*Init) DoGetHealthClient

func (e *Init) DoGetHealthClient(name, url string) *health.Client

DoGetHealthClient creates a new Health Client for the provided name and url

func (*Init) DoGetInteractivesAPIClient

func (e *Init) DoGetInteractivesAPIClient(apiRouter *health.Client) (routes.InteractivesAPIClient, error)

DoGetInteractivesApiClient returns an interactives api client

func (*Init) DoGetStorageProvider

func (e *Init) DoGetStorageProvider(cfg *config.Config, downloadClient storage.DownloadServiceAPIClient) (storage.Provider, error)

type Initialiser

type Initialiser interface {
	DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer
	DoGetHealthClient(name, url string) *health.Client
	DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)
	DoGetInteractivesAPIClient(apiRouter *health.Client) (routes.InteractivesAPIClient, error)
	DoGetStorageProvider(cfg *config.Config, c storage.DownloadServiceAPIClient) (storage.Provider, error)
	DoGetDownloadServiceAPIClient(cfg *config.Config) (storage.DownloadServiceAPIClient, error)
}

Initialiser defines the methods to initialise external services

type Service

type Service struct {
	Config                   *config.Config
	HealthCheck              HealthChecker
	Server                   HTTPServer
	ServiceList              *ExternalServiceList
	StorageProvider          storage.Provider
	APIRouter                *health.Client
	DownloadServiceAPIClient storage.DownloadServiceAPIClient
}

Service contains the healthcheck, server and serviceList for the controller

func New

func New(cfg *config.Config, serviceList *ExternalServiceList) *Service

New creates a new service

func (*Service) Close

func (s *Service) Close(ctx context.Context) error

Close gracefully shuts the service down in the required order, with timeout

func (*Service) Init

func (s *Service) Init(ctx context.Context) (err error)

Init initialises all the service dependencies, including healthcheck with checkers, api and middleware

func (*Service) Run

func (s *Service) Run(ctx context.Context, svcErrors chan error)

Run starts an initialised service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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