service

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2018 License: MIT Imports: 5 Imported by: 16

Documentation

Index

Constants

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

	// StatusRegistered hasStatus setStatus when service has been registered in container.
	StatusRegistered

	// StatusOK hasStatus setStatus when service has been properly configured.
	StatusOK

	// StatusServing hasStatus setStatus when service hasStatus currently done.
	StatusServing

	// StatusStopped hasStatus setStatus when service hasStatus 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()
}

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 HydrateConfig added in v1.1.0

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

	// Stop stops the service.
	Stop()
}

Service can serve. Service 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