1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-16 09:58:33 +02:00
go-micro/registry/watcher.go
2023-04-26 02:16:34 +02:00

57 lines
1.1 KiB
Go

package registry
import "time"
// Watcher is an interface that returns updates
// about services within the registry.
type Watcher interface {
// Next is a blocking call
Next() (*Result, error)
Stop()
}
// Result is returned by a call to Next on
// the watcher. Actions can be create, update, delete.
type Result struct {
Service *Service
Action string
}
// EventType defines registry event type.
type EventType int
const (
// Create is emitted when a new service is registered.
Create EventType = iota
// Delete is emitted when an existing service is deregsitered.
Delete
// Update is emitted when an existing servicec is updated.
Update
)
// String returns human readable event type.
func (t EventType) String() string {
switch t {
case Create:
return "create"
case Delete:
return "delete"
case Update:
return "update"
default:
return "unknown"
}
}
// Event is registry event.
type Event struct {
// Timestamp is event timestamp
Timestamp time.Time
// Service is registry service
Service *Service
// Id is registry id
Id string
// Type defines type of event
Type EventType
}