micro: rewrite options to support multiple building blocks

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-01-29 13:17:32 +03:00
parent ac8a3a12c4
commit 827d467077
57 changed files with 1283 additions and 644 deletions

56
register/watcher.go Normal file
View File

@@ -0,0 +1,56 @@
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()
}
// Result is returned by a call to Next on
// the watcher. Actions can be create, update, delete
type Result struct {
Action string
Service *Service
}
// EventType defines register 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 deregistered
Delete
// Update is emitted when an existing service 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 register event
type Event struct {
// Id is register id
Id string
// Type defines type of event
Type EventType
// Timestamp is event timestamp
Timestamp time.Time
// Service is register service
Service *Service
}