Documentation ¶
Index ¶
- Variables
- func Close() error
- func FindFreeLocalAddress(from, to int) (freeaddr string, err error)
- func FindFreePort(from, to int) (freeport int, err error)
- func FreePort() (freeport int, err error)
- func GetObservedServiceNames() []string
- func LocalFreeAddr() (freeaddr string, err error)
- func LocalFreeIPv6Addr() (freeaddr string, err error)
- func Observe(name string) error
- func Port(s Service) int
- func SetServiceStatus(s Service, status Status) error
- func Unregister(s Service) error
- type Configure
- type Event
- type Filter
- type FnUnregister
- type ObserveFilter
- type ObserverEvent
- type Option
- func AddFilter(f Filter) Option
- func AddObserveFilter(f ObserveFilter) Option
- func WithLoglevel(level logrus.Level) Option
- func WithMainTopic(topic string) Option
- func WithObserverEvent(ev ObserverEvent) Option
- func WithPubsub(pb pubsub.Pubsub) Option
- func WithRegisterInterval(duration time.Duration) Option
- func WithTimeout(timeout time.Duration) Option
- type Options
- type Pong
- type Registry
- type Service
- type Status
- type Timestamps
Constants ¶
This section is empty.
Variables ¶
var ( //DefaultTimeout timeout for GetService DefaultTimeout = 100 * time.Millisecond //DefaultRegisterInterval time between 2 registration DefaultRegisterInterval = 20 * time.Second //DefaultCheckDueInterval time between 2 checks DefaultCheckDueInterval = 200 * time.Millisecond //DefaultMainTopic default message base. All topics will start with this message DefaultMainTopic = "registry" //DefaultDueDurationFactor service expire when currentTime > lastRegisteredTime + registerInternal * dueDrationFactor DefaultDueDurationFactor = float32(1.5) )
var ( //ErrNotFound when no service found ErrNotFound = errors.New("no service found") //ErrNoDefaultInstance when intance singleton has not been set ErrNoDefaultInstance = errors.New("default instance has not been set, call SetDefault before") )
var ErrNoFreePort = errors.New("no free port available")
ErrNoFreePort when no free port is available
Functions ¶
func FindFreeLocalAddress ¶ added in v0.0.7
FindFreeLocalAddress return local free address using range of port (127.0.0.1:23432)
func FindFreePort ¶ added in v0.0.7
FindFreePort from range of integer
func GetObservedServiceNames ¶ added in v0.4.5
func GetObservedServiceNames() []string
func LocalFreeAddr ¶ added in v0.0.7
LocalFreeAddr return local free address (127.0.0.1:34545)
func LocalFreeIPv6Addr ¶ added in v0.0.7
LocalFreeIPv6Addr return local free address ([::1]:34545)
func SetServiceStatus ¶ added in v0.4.3
Types ¶
type Event ¶ added in v0.0.6
type Event string
Event represent event (register|unregister|unavailbale)
type Filter ¶
Filter used for filtering service do not return nil Ex Load Balancing
func LocalhostFilter ¶
func LocalhostFilter() Filter
LocalhostFilter return true if hostname is equals to service host
func PassingFilter ¶ added in v0.4.0
func PassingFilter() Filter
type FnUnregister ¶
type FnUnregister func()
FnUnregister call this func for unregister the service
func Register ¶ added in v0.0.6
func Register(s Service) (FnUnregister, error)
Register register a new service
Call SetDefault before use
type ObserveFilter ¶ added in v0.0.6
ObserveFilter used to accept (or not) new registered service.
Ex: you want only service on same host
func LocalhostOFilter ¶ added in v0.0.6
func LocalhostOFilter() ObserveFilter
LocalhostOFilter accept only service on the same machine
type ObserverEvent ¶ added in v0.0.6
ObserverEvent event tigered
type Option ¶
type Option func(opts *Options)
Option option func
func AddObserveFilter ¶ added in v0.0.6
func AddObserveFilter(f ObserveFilter) Option
AddObserveFilter adding filter
func WithLoglevel ¶ added in v0.2.0
WithLoglevel set log level
func WithMainTopic ¶ added in v0.2.0
WithMainTopic all topic will start with topic. Usefull in multi-tenancy
func WithObserverEvent ¶ added in v0.2.0
func WithObserverEvent(ev ObserverEvent) Option
WithObserverEvent set handler for Observer Event
func WithPubsub ¶ added in v0.0.6
WithPubsub initialyse service registry with nats connection
func WithRegisterInterval ¶ added in v0.2.0
WithRegisterInterval time between 2 register publish
func WithTimeout ¶ added in v0.2.0
WithTimeout define GetService timeout option
* GetService look service in his cache, if cache is empty, or if filtered services is empty then a ping is sent. GetService wait until a new registered service
type Options ¶
type Options struct { KVOption map[string]interface{} // contains filtered or unexported fields }
Options all configurable option
type Pong ¶
type Pong struct { Service Timestamps *Timestamps `json:"t,omitempty"` Status Status `json:"status,omitempty"` }
Pong response to ping
type Registry ¶
type Registry interface { Register(s Service) (FnUnregister, error) Unregister(s Service) error GetServices(name string) ([]Service, error) GetService(name string, filters ...Filter) (*Service, error) Observe(serviceName string) error GetObservedServiceNames() []string Subscribers() []string Close() error SetServiceStatus(s Service, status Status) error GetRegisteredServices() []Service }
Registry Register, Unregister
func GetDefault ¶ added in v0.1.0
GetDefault return default instance. return err if no default instance had been set
func NewRegistry ¶ added in v0.0.8
NewRegistry create a new service registry instance
type Service ¶
type Service struct { //Network tcp/unix/tpc6 Network string `json:"net,omitempty"` //Bind address Address string `json:"add,omitempty"` //URL base used for communicate with this service URL string `json:"url,omitempty"` //Name service name Name string `json:"name,omitempty"` //Version semver version Version string `json:"v,omitempty"` //Host Host string `json:"h,omitempty"` //KV key value pair KV map[string]string `json:"kv,omitempty"` // contains filtered or unexported fields }
Service service struct
func GetRegisteredServices ¶ added in v0.4.3
func GetService ¶ added in v0.0.8
GetService find service with service name
Call SetDefault before use
func GetServices ¶ added in v0.0.8
GetServices return all registered service
Call SetDefault before use
type Status ¶ added in v0.4.0
type Status int
func (*Status) FromString ¶ added in v0.4.0
func (Status) MarshalJSON ¶ added in v0.4.0
func (*Status) UnmarshalJSON ¶ added in v0.4.0
type Timestamps ¶
type Timestamps struct { //Registered date registered in nanoseconds (unix timestamp in milliseconds) Registered int64 //expiration duration in milliseconds Duration int }
Timestamps define registered datetime and expiration duration