github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/registry/watcher.go (about)

     1  // Licensed under the Apache License, Version 2.0 (the "License");
     2  // you may not use this file except in compliance with the License.
     3  // You may obtain a copy of the License at
     4  //
     5  //     https://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS,
     9  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  // See the License for the specific language governing permissions and
    11  // limitations under the License.
    12  //
    13  // Original source: github.com/micro/go-micro/v3/registry/watcher.go
    14  
    15  package registry
    16  
    17  import "time"
    18  
    19  // Watcher is an interface that returns updates
    20  // about services within the registry.
    21  type Watcher interface {
    22  	// Next is a blocking call
    23  	Next() (*Result, error)
    24  	Stop()
    25  }
    26  
    27  // Result is returned by a call to Next on
    28  // the watcher. Actions can be create, update, delete
    29  type Result struct {
    30  	Action  string
    31  	Service *Service
    32  }
    33  
    34  // EventType defines registry event type
    35  type EventType int
    36  
    37  const (
    38  	// Create is emitted when a new service is registered
    39  	Create EventType = iota
    40  	// Delete is emitted when an existing service is deregistered
    41  	Delete
    42  	// Update is emitted when an existing service is updated
    43  	Update
    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  }
    59  
    60  // Event is registry event
    61  type Event struct {
    62  	// Id is registry id
    63  	Id string
    64  	// Type defines type of event
    65  	Type EventType
    66  	// Timestamp is event timestamp
    67  	Timestamp time.Time
    68  	// Service is registry service
    69  	Service *Service
    70  }