regist

package module
v0.0.0-...-adcefb9 Latest Latest
Warning

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

Go to latest
Published: May 6, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceNotFound is returned when a key is not found in the register.
	ErrServiceNotFound = errors.New("service not found")

	// ErrServiceAlreadyRegistered is returned when trying to set an already registered service.
	ErrServiceAlreadyRegistered = errors.New("service already registered")

	// ErrServiceAlreadyInPool is returned when trying to update a pool with the address already there.
	ErrServiceAlreadyInPool = errors.New("service already in the pool")
)

Functions

func GetHTTPRouter

func GetHTTPRouter(register *Register) *httprouter.Router

GetHTTPRouter adds all the necessary http handlers for the register.

Types

type Entry

type Entry struct {
	Meta `json:"_meta"`
	ServicePool
}

Entry represents, at the moment, the value of a key in a register.

type EntryMap

type EntryMap map[string]Entry

EntryMap is a key value. Not safe on concurrent access.

func (EntryMap) Copy

func (em EntryMap) Copy() EntryMap

Copy returns a copy of all the entries in the map.

func (EntryMap) Get

func (em EntryMap) Get(key string) (entry Entry, err error)

Get retrieves a key from the entry map.

func (EntryMap) Has

func (em EntryMap) Has(key string) bool

Has returns a boolean value whether the key is present or not.

func (EntryMap) Set

func (em EntryMap) Set(key string, entry Entry) error

Set inserts a key into the map, if its not there already. It also take scare of updating metadata on the Entry object.

func (EntryMap) Update

func (em EntryMap) Update(key string, entry Entry) error

Update performs an update on the value of an existing key.

type Meta

type Meta struct {
	Revision  int       `json:"revision"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Meta stores metadata about an entry in the EntryMap.

type Register

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

Register stores and allows manipulation of itself.

func New

func New() *Register

New instantiates a new Register.

func (*Register) Get

func (reg *Register) Get(serviceName string) (Entry, error)

Get attempts to retrieve a registered service.

func (*Register) List

func (reg *Register) List() []Entry

List returns the all the entries of the register.

func (*Register) MarshalJSON

func (reg *Register) MarshalJSON() ([]byte, error)

MarshalJSON returns a custom serialisation of the object to bytes.

func (*Register) Set

func (reg *Register) Set(service Service) error

Set registers a new service in the register.

func (*Register) Update

func (reg *Register) Update(service Service) error

Update attempts to update a service with the incoming service.

type Service

type Service struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

Service stores details about a service.

type ServicePool

type ServicePool struct {
	Name        string          `json:"name"`
	AddressPool map[string]bool `json:"-"`
}

ServicePool stores a pool of services.

func (*ServicePool) MarshalJSON

func (sp *ServicePool) MarshalJSON() ([]byte, error)

MarshalJSON returns a custom serialisation of the object to bytes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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