core

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loggable

type Loggable interface {
	WithLogger(LoggerInterface)
}

Loggable determine possibility to inject LoggerInterface. Can be used to wire Source and Registry implementations

type LoggerInterface

type LoggerInterface interface {
	logrus.FieldLogger
}

LoggerInterface provides common log methods. This is replica for logrus.FieldLogger.

type Manager

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

Manager is built-in ManagerInterface implementation.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run contains next steps - Call Source.Fetch - Call Registry.Fetch - Check orphan Services fetched from Registry - Remove orphan Services - Register Services fetched from Source

type ManagerExitOnError

type ManagerExitOnError bool

ManagerExitOnError provide information how to handle errors and panics during manager.Run process.

type ManagerInterface

type ManagerInterface interface {
	Run(ctx context.Context) error
}

ManagerInterface is main unit between Source and Registry. Implementation must provide full cycle for fetch services from Source and register them into Registry.

func NewManager

func NewManager(source Source, registry Registry, logger LoggerInterface, exitOnError ManagerExitOnError) ManagerInterface

NewManager provider built-in ManagerInterface implementation

type Node added in v1.2.0

type Node struct {
	Node       string             `json:","`
	Address    string             `json:","`
	Datacenter *string            `json:",omitempty"`
	NodeMeta   *map[string]string `json:",omitempty"`
}

Node contains info about host/node/server, hosting service. Used for catalog registration in consul.

type Registry

type Registry interface {
	Fetch(ctx context.Context) (Services, error)
	Register(ctx context.Context, service *Service) error
	Deregister(ctx context.Context, service *Service) error
}

Registry is endpoint/upstream for storing information about Services fetched from Source. Registry must implements 3 methods to make store clean: fetch current state, deregister orphans, register/update incoming

type Scheduler

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

Scheduler is simple wrapper for ManagerInterface. Scheduler provides possibility to call Manager.Run with constant interval passed to time.Ticker.

func NewScheduler

func NewScheduler(ticker *time.Ticker, manager ManagerInterface, logger LoggerInterface) *Scheduler

NewScheduler provides Scheduler with predefined time.Ticker, ManagerInterface and LoggerInterface

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

Run start listen time.Ticker ticks until context.Context canceled.

type Service

type Service struct {
	Name    string             `json:","`
	Address string             `json:","`
	ID      *string            `json:",omitempty"`
	Port    *int               `json:",omitempty"`
	Tags    *[]string          `json:",omitempty"`
	Meta    *map[string]string `json:",omitempty"`
	Node    *Node              `json:",omitempty"`
}

Service contains all the necessary information for further registration in Registry

func (*Service) RegistrationID

func (s *Service) RegistrationID() string

RegistrationID generate identification for registration in Registry.

func (*Service) Validate

func (s *Service) Validate(ctx context.Context, checks ...ValidationFunc) error

Validate process validation to check required fields for Service, such as Service.Name and Service.Address Also there is a possibility to pass your own additional checks

type Services

type Services []*Service

Services is simple helper for hold slice of Service's

func (Services) IDs

func (s Services) IDs() []string

IDs return slice of Service.RegistrationID

func (Services) Lookup

func (s Services) Lookup(id string) *Service

Lookup return Service by Service.RegistrationID, if found

type Source

type Source interface {
	Fetch(ctx context.Context) (Services, error)
}

Source provides information about Services to be registered in Registry. Source does not know about changes between Fetch calls, it must just return actual state of source.

type ValidationFunc added in v1.2.0

type ValidationFunc func(context.Context, *Service) error

ValidationFunc is a func providing additional validation, called by Source or Registry

Directories

Path Synopsis
registry
source

Jump to

Keyboard shortcuts

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