registry

package module
v0.0.0-...-0c25fb7 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

Registry service Go Report Card

@license Apache-2.0

go get -v github.com/geniusrabbit/registry

Service observer environment

To automatic register any docker service by observer in consul you have to configure your container. Recommended to use docker LABELs.

LABEL maintainer="..."

LABEL service.name={somename}
LABEL service.weight=1
LABEL service.port=8080 # Used as default in address ip:port
LABEL service.public="true"
# Healhcheck options
LABEL service.check.interval=5s
LABEL service.check.timeout=10s
LABEL service.check.httpaddr=http://{{address}}/v1/check
# Tags
LABEL service.tag_{TAG_NAME}={VALUE} # => {TAG_NAME}={VALUE}

Also available environment variables.

ENV SERVICE_NAME={somename}
ENV SERVICE_PORT=8080
ENV SERVICE_WEIGHT=1
# Healhcheck options
ENV CHECK_HTTP=http://{{address}}/v1/check
ENV CHECK_INTERVAL=5s
ENV CHECK_TIMEOUT=2s
# Tags
ENV TAG_{TAG_NAME}={VALUE} # => {TAG_NAME}={VALUE}

Example of your service Dockerfile

FROM ubuntu:trusty

LABEL service.name=archivarius
LABEL service.weight=1
LABEL service.port=8080

LABEL service.check.interval=5s
LABEL service.check.timeout=2s
# {{address}} automaticaly replaced to real address of service
LABEL service.check.httpaddr=http://{{address}}/v1/check

EXPOSE {port}, ...

Build observer service

make build_docker_observer

Run service

docker run -itd --restart always \
   --name=service-observer \
   --link consul:registry \
   -v /var/run/docker.sock:/var/run/docker.sock \
   service-observer

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnbindedConfig      = errors.New("Config is not bind")
	ErrInvalidKeyParam     = errors.New("Invalid key params")
	ErrInvalidTargetStruct = errors.New("Invalid bind target struct")
)

Errors set

Functions

func Bind

func Bind(conf interface{}, sep ...string) error

Bind config for authoupdate

func RegisterStore

func RegisterStore(st Storage)

RegisterStore in heap

func Subscribe

func Subscribe(conf interface{}, key string, b bindKeyUpdater) error

Subscribe updater for config

func Supervisor

func Supervisor(interval time.Duration)

Supervisor of auto refresh

func Unsubscribe

func Unsubscribe(conf interface{}, key string, b bindKeyUpdater) error

Unsubscribe updater for config

func WrapConf

func WrapConf(conf interface{}, tagName string, pathSeparator rune) bindUpdater

WrapConf bind field updater

Types

type Balancer

type Balancer interface {
	// Borrow service from upstream
	Borrow(service string) Connect

	// Return connect back to pool
	Return(conn Connect, errResult error)

	// Refresh current state
	Refresh() error

	// Supervisor loop
	Supervisor(interval time.Duration)

	// Stop supervisor
	Stop()
}

Balancer of service

func NewBalancer

func NewBalancer(discovery service.Discovery, maxIdelConnection int) Balancer

NewBalancer object

type BindHeap

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

BindHeap base type

var (
	DefaultBindHeap BindHeap
)

Global vars

func (*BindHeap) Bind

func (bh *BindHeap) Bind(conf interface{}, sep ...string) error

Bind config for authoupdate

func (*BindHeap) RegisterStore

func (bh *BindHeap) RegisterStore(st Storage)

RegisterStore in heap

func (*BindHeap) Subscribe

func (bh *BindHeap) Subscribe(conf interface{}, key string, b bindKeyUpdater) error

Subscribe updater for config

func (*BindHeap) Supervisor

func (bh *BindHeap) Supervisor(interval time.Duration)

Supervisor of auto refresh

func (*BindHeap) Unsubscribe

func (bh *BindHeap) Unsubscribe(conf interface{}, key string, b bindKeyUpdater) error

Unsubscribe updater for config

type Connect

type Connect interface {
	Host() string
	Return(resultError error)
}

Connect interface

type Storage

type Storage interface {
	// Subscribe config key updater
	Subscribe(f func(key string, value interface{}))

	// Discovery services
	Discovery() service.Discovery

	// Supervisor of auto refresh
	Supervisor(interval time.Duration)
}

Storage connector

type Upstream

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

Upstream connection queue

func NewUpstream

func NewUpstream(idleCount int) *Upstream

NewUpstream queue

func (*Upstream) Borrow

func (up *Upstream) Borrow() Connect

Borrow next connection

func (*Upstream) Next

func (up *Upstream) Next() Connect

Next connection

func (*Upstream) Reset

func (up *Upstream) Reset()

Reset all active streams

func (*Upstream) Return

func (up *Upstream) Return(conn Connect, resultError error)

Return connection into queue

func (*Upstream) Update

func (up *Upstream) Update(items ...upstreamItem)

Update upstream items

type UpstreamServiceItem

type UpstreamServiceItem struct {
	Service  *service.Service
	Upstream *Upstream
	// contains filtered or unexported fields
}

UpstreamServiceItem wrapper

func UpstreamService

func UpstreamService(srv *service.Service) *UpstreamServiceItem

UpstreamService wrapper function

func (*UpstreamServiceItem) Connect

func (it *UpstreamServiceItem) Connect(up *Upstream) Connect

Connect service interface

func (*UpstreamServiceItem) Host

func (it *UpstreamServiceItem) Host() string

Host name with port

func (*UpstreamServiceItem) Return

func (it *UpstreamServiceItem) Return(resultError error)

Return service to upstream pool

func (*UpstreamServiceItem) SetWeight

func (it *UpstreamServiceItem) SetWeight(weight int)

SetWeight of service

func (*UpstreamServiceItem) Weight

func (it *UpstreamServiceItem) Weight() int

Weight of service

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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