service

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExternalServiceList

type ExternalServiceList struct {
	ImageAPI                    bool
	FilesService                bool
	HealthCheck                 bool
	KafkaImagePublishedConsumer bool
	KafkaFilePublishedConsumer  bool
	S3Private                   bool
	S3Public                    bool
	S3ClientV2                  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) GetFilesService added in v1.3.0

func (e *ExternalServiceList) GetFilesService(ctx context.Context, cfg *config.Config) file.FilesService

GetFilesService creates files service and sets the FilesService flag to true

func (*ExternalServiceList) GetHTTPServer

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

GetHTTPServer creates an http server and sets the Server flag to true

func (*ExternalServiceList) GetHealthCheck

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

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

func (*ExternalServiceList) GetImageAPIClient added in v0.3.0

func (e *ExternalServiceList) GetImageAPIClient(cfg *config.Config) event.ImageAPIClient

GetImageAPIClient creates an ImageAPI client and sets the ImageAPI flag to true

func (*ExternalServiceList) GetKafkaFilePublishedConsumer added in v1.3.0

func (e *ExternalServiceList) GetKafkaFilePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)

GetKafkaFilePublishedConsumer creates a Kafka consumer and sets the consumer flag to true

func (*ExternalServiceList) GetKafkaImagePublishedConsumer added in v1.3.0

func (e *ExternalServiceList) GetKafkaImagePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)

GetKafkaImagePublishedConsumer creates a Kafka consumer and sets the consumer flag to true

func (*ExternalServiceList) GetS3ClientV2 added in v1.2.0

func (e *ExternalServiceList) GetS3ClientV2(cfg *config.Config, bucketName string) (file.S3ClientV2, error)

GetS3ClientV2 returns S3 clients private and public. They share the same AWS session.

func (*ExternalServiceList) GetS3Clients added in v0.4.0

func (e *ExternalServiceList) GetS3Clients(cfg *config.Config) (s3Private event.S3Reader, s3Public event.S3Writer, err error)

GetS3Clients returns S3 clients private and public. They share the same AWS session.

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) DoGetFilesService added in v1.3.0

func (e *Init) DoGetFilesService(_ context.Context, cfg *config.Config) file.FilesService

DoGetFilesService returns a files service backend

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) DoGetImageAPIClient added in v0.3.0

func (e *Init) DoGetImageAPIClient(cfg *config.Config) event.ImageAPIClient

DoGetImageAPIClient returns an Image API client

func (*Init) DoGetKafkaFilePublishedConsumer added in v1.3.0

func (e *Init) DoGetKafkaFilePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)

func (*Init) DoGetKafkaImagePublishedConsumer added in v1.3.0

func (e *Init) DoGetKafkaImagePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)

DoGetKafkaImagePublishedConsumer returns a Kafka Consumer group

func (*Init) DoGetKafkaTopicConsumer added in v1.3.0

func (e *Init) DoGetKafkaTopicConsumer(ctx context.Context, cfg *config.Config, topic string) (KafkaConsumer, error)

func (*Init) DoGetS3Client added in v0.4.0

func (e *Init) DoGetS3Client(awsRegion, bucketName string) (event.S3Writer, error)

DoGetS3Client creates a new S3Client for the provided AWS region and bucket name.

func (*Init) DoGetS3ClientV2 added in v1.2.0

func (e *Init) DoGetS3ClientV2(awsRegion, bucketName string) (file.S3ClientV2, error)

func (*Init) DoGetS3ClientWithSession added in v0.7.0

func (e *Init) DoGetS3ClientWithSession(bucketName string, s *session.Session) event.S3Reader

DoGetS3ClientWithSession creates a new S3Clienter (extension of S3Client with Upload operations) for the provided bucket name, using an existing AWS session

type Initialiser

type Initialiser interface {
	DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer
	DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)
	DoGetImageAPIClient(cfg *config.Config) event.ImageAPIClient
	DoGetKafkaImagePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)
	DoGetKafkaFilePublishedConsumer(ctx context.Context, cfg *config.Config) (KafkaConsumer, error)
	DoGetS3Client(awsRegion, bucketName string) (event.S3Writer, error)
	DoGetS3ClientWithSession(bucketName string, s *session.Session) event.S3Reader
	DoGetS3ClientV2(awsRegion, bucketName string) (file.S3ClientV2, error)
	DoGetFilesService(ctx context.Context, cfg *config.Config) file.FilesService
}

Initialiser defines the methods to initialise external services

type KafkaConsumer added in v0.7.0

type KafkaConsumer interface {
	Start() error
	RegisterBatchHandler(ctx context.Context, batchHandler kafka.BatchHandler) error
	Checker(ctx context.Context, state *healthcheck.CheckState) error
	Stop() error
	StateWait(state kafka.State)
	Close(ctx context.Context) (err error)
}

type Service

type Service struct {
	Config                      *config.Config
	Server                      HTTPServer
	Router                      *mux.Router
	ServiceList                 *ExternalServiceList
	HealthCheck                 HealthChecker
	ImageAPICli                 event.ImageAPIClient
	KafkaImagePublishedConsumer KafkaConsumer
	KafkaFilePublishedConsumer  KafkaConsumer
	S3Public                    event.S3Writer
	S3Private                   event.S3Reader
	FilesClient                 file.FilesService
}

Service contains all the configs, server and clients to run the Image API

func Run

func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceList, buildTime, gitCommit, version string, svcErrors chan error) (svc *Service, err 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