github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/registry/watcher.go (about)

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