service

package
v0.1.1-experimental.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[S any](opts ...Option[S]) *S

New helps us to create a new Service with the provided options.

Types

type BaseService

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

BaseService is a base service that provides common functionality for all services.

func NewBaseService

func NewBaseService(
	cfg *config.Config,
	bsp BeaconStorageBackend,
	logger log.Logger,
) *BaseService

NewBaseService creates a new BaseService and applies the provided options.

func (*BaseService) AvailabilityStore

func (s *BaseService) AvailabilityStore(
	ctx context.Context,
) core.AvailabilityStore

AvailabilityStore returns the availability store from the BaseService.

func (*BaseService) BeaconCfg

func (s *BaseService) BeaconCfg() *params.BeaconChainConfig

BeaconCfg returns the configuration settings of the beacon node from the BaseService.

func (*BaseService) BeaconState

func (s *BaseService) BeaconState(ctx context.Context) state.BeaconState

BeaconState returns the beacon state from the BaseService.

func (*BaseService) BuilderCfg

func (s *BaseService) BuilderCfg() *builderconfig.Config

BuilderCfg returns the configuration settings of the builder from the BaseService.

func (*BaseService) Logger

func (s *BaseService) Logger() log.Logger

Logger returns the logger instance of the BaseService. It is used for logging messages in a structured manner.

func (*BaseService) Name

func (s *BaseService) Name() string

Name returns the name of the BaseService.

func (*BaseService) SetStatus

func (s *BaseService) SetStatus(err error)

SetStatus sets the status error of the BaseService.

func (BaseService) ShallowCopy

func (s BaseService) ShallowCopy(name string) BaseService

ShallowCopy copies the base service and replaces it's name.

func (*BaseService) Start

func (s *BaseService) Start(context.Context)

Start is an intentional no-op for the BaseService.

func (*BaseService) Status

func (s *BaseService) Status() error

Status is an intentional no-op for the BaseService.

func (*BaseService) WaitForHealthy

func (s *BaseService) WaitForHealthy(context.Context)

WaitForHealthy is an intentional no-op for the BaseService.

type Basic

type Basic interface {
	// Start spawns any goroutines required by the service.
	Start(ctx context.Context)
	// Name returns the name of the service.
	Name() string
	// Status returns error if the service is not considered healthy.
	Status() error
	// WaitForHealthy blocks until the service is healthy.
	WaitForHealthy(ctx context.Context)
}

Basic is the minimal interface for a service.

type BeaconStorageBackend

type BeaconStorageBackend interface {
	AvailabilityStore(ctx context.Context) core.AvailabilityStore
	BeaconState(ctx context.Context) state.BeaconState
}

BeaconStorageBackend is an interface that provides the beacon state to the runtime.

type Option

type Option[T any] func(*T) error

Option is a function type that takes a pointer to a Service and returns an error.

type Registry

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

Registry provides a useful pattern for managing services. It allows for ease of dependency management and ensures services dependent on others use the same references in memory.

func NewRegistry

func NewRegistry(opts ...RegistryOption) *Registry

NewRegistry starts a registry instance for convenience.

func (*Registry) FetchService

func (s *Registry) FetchService(service interface{}) error

FetchService takes in a struct pointer and sets the value of that pointer to a service currently stored in the service registry. This ensures the input argument is set to the right pointer that refers to the originally registered service.

func (*Registry) RegisterService

func (s *Registry) RegisterService(service Basic) error

RegisterService appends a service constructor function to the service registry.

func (*Registry) StartAll

func (s *Registry) StartAll(ctx context.Context)

StartAll initialized each service in order of registration.

func (*Registry) Statuses

func (s *Registry) Statuses(services ...string) map[string]error

Statuses returns a map of Service type -> error. The map will be populated with the results of each service.Status() method call.

func (*Registry) WaitForHealthy

func (s *Registry) WaitForHealthy(ctx context.Context, services ...string)

Statuses returns a map of Service type -> error. The map will be populated with the results of each service.Status() method call.

type RegistryOption

type RegistryOption func(*Registry) error

RegistryOption is a functional option for the Registry.

func WithLogger

func WithLogger(logger log.Logger) RegistryOption

WithLogger is an option to set the logger for the Registry.

func WithService

func WithService(svc Basic) RegistryOption

WithService is an Option that registers a service with the Registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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