2015-12-05 03:12:29 +02:00
|
|
|
package registry
|
|
|
|
|
2019-09-23 18:25:15 +02:00
|
|
|
import "time"
|
|
|
|
|
2015-12-05 04:05:06 +02:00
|
|
|
// Watcher is an interface that returns updates
|
|
|
|
// about services within the registry.
|
2015-12-05 03:12:29 +02:00
|
|
|
type Watcher interface {
|
2015-12-05 04:05:06 +02:00
|
|
|
// Next is a blocking call
|
2015-12-05 03:12:29 +02:00
|
|
|
Next() (*Result, error)
|
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2015-12-05 04:05:06 +02:00
|
|
|
// Result is returned by a call to Next on
|
2022-09-30 16:27:07 +02:00
|
|
|
// the watcher. Actions can be create, update, delete.
|
2015-12-05 03:12:29 +02:00
|
|
|
type Result struct {
|
|
|
|
Action string
|
|
|
|
Service *Service
|
|
|
|
}
|
2019-09-23 18:25:15 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// EventType defines registry event type.
|
2019-09-23 18:25:15 +02:00
|
|
|
type EventType int
|
|
|
|
|
|
|
|
const (
|
2022-09-30 16:27:07 +02:00
|
|
|
// Create is emitted when a new service is registered.
|
2019-09-23 18:25:15 +02:00
|
|
|
Create EventType = iota
|
2022-09-30 16:27:07 +02:00
|
|
|
// Delete is emitted when an existing service is deregsitered.
|
2019-09-23 18:25:15 +02:00
|
|
|
Delete
|
2022-09-30 16:27:07 +02:00
|
|
|
// Update is emitted when an existing servicec is updated.
|
2019-09-23 18:25:15 +02:00
|
|
|
Update
|
|
|
|
)
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// String returns human readable event type.
|
2019-09-23 18:25:15 +02:00
|
|
|
func (t EventType) String() string {
|
|
|
|
switch t {
|
|
|
|
case Create:
|
|
|
|
return "create"
|
|
|
|
case Delete:
|
|
|
|
return "delete"
|
|
|
|
case Update:
|
|
|
|
return "update"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Event is registry event.
|
2019-09-23 18:25:15 +02:00
|
|
|
type Event struct {
|
|
|
|
// Id is registry id
|
|
|
|
Id string
|
|
|
|
// Type defines type of event
|
|
|
|
Type EventType
|
|
|
|
// Timestamp is event timestamp
|
|
|
|
Timestamp time.Time
|
|
|
|
// Service is registry service
|
|
|
|
Service *Service
|
|
|
|
}
|