service

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusUndefined when service bus can not find the service.
	StatusUndefined = iota

	// StatusInactive when service has been registered in container.
	StatusInactive

	// StatusOK when service has been properly configured.
	StatusOK

	// StatusServing when service is currently done.
	StatusServing

	// StatusStopping when service is currently stopping.
	StatusStopping

	// StatusStopped when service being stopped.
	StatusStopped
)
View Source
const InitMethod = "Init"

InitMethod contains name of the method to be automatically invoked while service initialization. Must return (bool, error). Container can be requested as well. Config can be requested in a form of service.Config or pointer to service specific config struct (automatically unmarshalled), config argument must implement service.HydrateConfig.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	// get nested config section (sub-map), returns nil if section not found.
	Get(service string) Config

	// Unmarshal unmarshal config data into given struct.
	Unmarshal(out interface{}) error
}

Config provides ability to slice configuration sections and unmarshal configuration data into given structure.

type Container

type Container interface {
	// Register add new service to the container under given name.
	Register(name string, service interface{})

	// Reconfigure configures all underlying services with given configuration.
	Init(cfg Config) error

	// Check if svc has been registered.
	Has(service string) bool

	// get returns svc instance by it's name or nil if svc not found. Method returns current service status
	// as second value.
	Get(service string) (svc interface{}, status int)

	// Serve all configured services. Non blocking.
	Serve() error

	// Close all active services.
	Stop()

	// List service names.
	List() []string
}

Container controls all internal RR services and provides plugin based system.

func NewContainer

func NewContainer(log logrus.FieldLogger) Container

NewContainer creates new service container.

type DefaultsConfig added in v1.6.5

type DefaultsConfig interface {
	// InitDefaults allows to init blank config with pre-defined set of default values.
	InitDefaults() error
}

DefaultsConfig declares ability to be initated without config data provided.

type HydrateConfig added in v1.6.5

type HydrateConfig interface {
	// Hydrate must populate config values using given config source.
	// Must return error if config is not valid.
	Hydrate(cfg Config) error
}

HydrateConfig provides ability to automatically hydrate config with values using service.Config as the source.

type Service

type Service interface {
	// Serve serves.
	Serve() error

	// Detach stops the service.
	Stop()
}

Service can serve. Services can provide Init method which must return (bool, error) signature and might accept other services and/or configs as dependency.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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