Files
micro/register/watcher.go
Vasiliy Tolstov a00cf2c8d9
Some checks failed
coverage / build (push) Failing after 55s
test / test (push) Successful in 3m39s
register: watcher fixes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-28 14:51:10 +03:00

60 lines
1.4 KiB
Go

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