go-micro.dev/v5@v5.12.0/registry/watcher.go (about)

     1  package registry
     2  
     3  import "time"
     4  
     5  // Watcher is an interface that returns updates
     6  // about services within the registry.
     7  type Watcher interface {
     8  	// Next is a blocking call
     9  	Next() (*Result, error)
    10  	Stop()
    11  }
    12  
    13  // Result is returned by a call to Next on
    14  // the watcher. Actions can be create, update, delete.
    15  type Result struct {
    16  	Service *Service
    17  	Action  string
    18  }
    19  
    20  // EventType defines registry event type.
    21  type EventType int
    22  
    23  const (
    24  	// Create is emitted when a new service is registered.
    25  	Create EventType = iota
    26  	// Delete is emitted when an existing service is deregsitered.
    27  	Delete
    28  	// Update is emitted when an existing servicec is updated.
    29  	Update
    30  )
    31  
    32  // String returns human readable event type.
    33  func (t EventType) String() string {
    34  	switch t {
    35  	case Create:
    36  		return "create"
    37  	case Delete:
    38  		return "delete"
    39  	case Update:
    40  		return "update"
    41  	default:
    42  		return "unknown"
    43  	}
    44  }
    45  
    46  // Event is registry event.
    47  type Event struct {
    48  	// Timestamp is event timestamp
    49  	Timestamp time.Time
    50  	// Service is registry service
    51  	Service *Service
    52  	// Id is registry id
    53  	Id string
    54  	// Type defines type of event
    55  	Type EventType
    56  }