registry

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Del      = "DEL"
	SRem     = "SREM"
	Keys     = "KEYS"
	SAdd     = "SADD"
	Set      = "SET"
	Get      = "GET"
	SMembers = "SMEMBERS"
)
View Source
const ModuleInfoRedisKey redisKey = "gserver:module:info"
View Source
const RegisterRedisKey redisKey = "gserver:modules"

Variables

View Source
var (
	DefaultRegistry = newRedisRegistry()
	ErrNotFound     = errors.New("not found")
)

Functions

func Deregister

func Deregister(s *Service) error

Deregister a service node

func Register

func Register(s *Service, opts ...RegisterOption) error

Register a service node. Additionally supply options such as TTL.

func String

func String() string

Types

type Endpoint

type Endpoint struct {
	Name     string            `json:"name"`
	Request  *Value            `json:"request"`
	Response *Value            `json:"response"`
	Metadata map[string]string `json:"metadata"`
}

type Node

type Node struct {
	Id       string            `json:"id"`
	Address  string            `json:"address"`
	Port     int               `json:"port"`
	Metadata map[string]string `json:"metadata"`
}

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

func RedisConn

func RedisConn(host string, password string) Option

func Secure

func Secure(b bool) Option

Secure communication with the registry

func TLSConfig

func TLSConfig(t *tls.Config) Option

Specify TLS Config

func Timeout

func Timeout(t time.Duration) Option

type Options

type Options struct {
	Addrs         []string
	Timeout       time.Duration
	Secure        bool
	TLSConfig     *tls.Config
	Context       context.Context
	GroupID       int
	RedisHost     string
	RedisPassword string
}

type RedisService

type RedisService struct {
	Name    string // service name
	Address string // service address
}

type RegisterOption

type RegisterOption func(*RegisterOptions)

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

type RegisterOptions

type RegisterOptions struct {
	TTL     time.Duration
	Context context.Context
}

type Registry

type Registry interface {
	Options() Options
	Register(*Service, ...RegisterOption) error
	Deregister(*Service) error
	GetService(string) ([]*Service, error)
	ListServices() ([]*Service, error)
	String() string
	Clean(typeName string) error
	Check(string) bool
}

The registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}

func NewConsulRegistry

func NewConsulRegistry(opts ...Option) Registry

func NewRedisRegistry

func NewRedisRegistry(opts ...Option) Registry

type Result

type Result struct {
	Action  string
	Service *Service
}

Result is returned by a call to Next on the watcher. Actions can be create, update, delete

type Service

type Service struct {
	Name      string            `json:"name"`
	Version   string            `json:"version"`
	Metadata  map[string]string `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
	ID        string            `json:"id"`
	Address   string            `json:"address"`
}

func GetService

func GetService(name string) ([]*Service, error)

Retrieve a service. A slice is returned since we separate Name/Version.

func ListServices

func ListServices() ([]*Service, error)

List the services. Only returns service names

type Value

type Value struct {
	Name   string   `json:"name"`
	Type   string   `json:"type"`
	Values []*Value `json:"values"`
}

type WatchOption

type WatchOption func(*WatchOptions)

func WatchService

func WatchService(name string) WatchOption

Watch a service

type WatchOptions

type WatchOptions struct {
	Service string
	Context context.Context
}

Specify a service to watch If blank, the watch is for all services

type Watcher

type Watcher interface {
	// Next is a blocking call
	Next() (*Result, error)
	Stop()
}

Watcher is an interface that returns updates about services within the registry.

Jump to

Keyboard shortcuts

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