service

package
v0.0.0-...-86b9d59 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBaseURL

func ParseBaseURL(bindaddr, baseurl string) (server, prefix string, err error)

ParseBaseURL figures out this instance's scheme, host, port and endpoint prefix. These pieces of info are used to strip optional endpoint prefixes from incomimg requests and to help swaggerui construct self-referential URLs.

If baseurl is set, then use it exclusively. Else if bindaddr has a missing or 0.0.0.0 host, use os.Hostname() Else use host and port from bindaddr.

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) GetAWS

func (e *ExternalServiceList) GetAWS() (*aws.Clients, error)

func (*ExternalServiceList) GetDatabase

func (e *ExternalServiceList) GetDatabase(driverName, dsn string) (*database.Database, 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

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 {
	Handler(w http.ResponseWriter, req *http.Request)
	Start(ctx context.Context)
	Stop()
	AddCheck(name string, checker healthcheck.Checker) (err error)
}

HealthChecker defines the required methods from Healthcheck

type Init

type Init struct{}

Init implements the Initialiser interface to initialise dependencies

func (*Init) DoGetAWS

func (e *Init) DoGetAWS() (*aws.Clients, error)

func (*Init) DoGetDatabase

func (e *Init) DoGetDatabase(driverName, dsn string) (*database.Database, 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

type Initialiser

type Initialiser interface {
	DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer
	DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)
	DoGetAWS() (*aws.Clients, error)
	DoGetDatabase(driverName, dsn string) (*database.Database, error)
}

Initialiser defines the methods to initialise external services

type Service

type Service struct {
	Config      *config.Config
	Server      HTTPServer
	ServiceList *ExternalServiceList
	HealthCheck HealthChecker
}

Service contains all the configs, server and clients to run the dp-topic-api API

func Run

func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceList, buildTime, gitCommit, version string, svcErrors chan error) (*Service, error)

Run the service

func (*Service) Close

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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