2021-01-29 13:17:32 +03:00
|
|
|
package register
|
2015-12-05 04:12:29 +03:00
|
|
|
|
2019-09-23 19:25:15 +03:00
|
|
|
import "time"
|
|
|
|
|
2015-12-05 05:05:06 +03:00
|
|
|
// Watcher is an interface that returns updates
|
2021-01-29 13:17:32 +03:00
|
|
|
// about services within the register.
|
2015-12-05 04:12:29 +03:00
|
|
|
type Watcher interface {
|
2015-12-05 05:05:06 +03:00
|
|
|
// Next is a blocking call
|
2015-12-05 04:12:29 +03:00
|
|
|
Next() (*Result, error)
|
2021-03-06 19:45:13 +03:00
|
|
|
// Stop stops the watcher
|
2015-12-05 04:12:29 +03:00
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2015-12-05 05:05:06 +03:00
|
|
|
// Result is returned by a call to Next on
|
|
|
|
// the watcher. Actions can be create, update, delete
|
2015-12-05 04:12:29 +03:00
|
|
|
type Result struct {
|
2021-03-06 19:45:13 +03:00
|
|
|
// Service holds register service
|
2015-12-05 04:12:29 +03:00
|
|
|
Service *Service
|
2021-03-06 19:45:13 +03:00
|
|
|
// Action holds the action
|
|
|
|
Action string
|
2015-12-05 04:12:29 +03:00
|
|
|
}
|
2019-09-23 19:25:15 +03:00
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
// EventType defines register event type
|
2019-09-23 19:25:15 +03:00
|
|
|
type EventType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Create is emitted when a new service is registered
|
|
|
|
Create EventType = iota
|
2020-07-16 18:33:11 +03:00
|
|
|
// Delete is emitted when an existing service is deregistered
|
2019-09-23 19:25:15 +03:00
|
|
|
Delete
|
2020-07-16 18:33:11 +03:00
|
|
|
// Update is emitted when an existing service is updated
|
2019-09-23 19:25:15 +03:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
// Event is register event
|
2019-09-23 19:25:15 +03:00
|
|
|
type Event struct {
|
|
|
|
// Timestamp is event timestamp
|
|
|
|
Timestamp time.Time
|
2021-01-29 13:17:32 +03:00
|
|
|
// Service is register service
|
2019-09-23 19:25:15 +03:00
|
|
|
Service *Service
|
2021-04-27 08:32:47 +03:00
|
|
|
// ID is register id
|
|
|
|
ID string
|
2021-03-06 19:45:13 +03:00
|
|
|
// Type defines type of event
|
|
|
|
Type EventType
|
2019-09-23 19:25:15 +03:00
|
|
|
}
|