gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/runtime/runtime.go (about)

     1  // Package runtime is a service runtime manager
     2  package runtime
     3  
     4  import "time"
     5  
     6  var (
     7  	// DefaultRuntime is default micro runtime
     8  	DefaultRuntime Runtime = NewRuntime()
     9  	// DefaultName is default runtime service name
    10  	DefaultName = "go.micro.runtime"
    11  )
    12  
    13  // Runtime is a service runtime manager
    14  type Runtime interface {
    15  	// Init initializes runtime
    16  	Init(...Option) error
    17  	// Create registers a service
    18  	Create(*Service, ...CreateOption) error
    19  	// Read returns the service
    20  	Read(...ReadOption) ([]*Service, error)
    21  	// Update the service in place
    22  	Update(*Service) error
    23  	// Remove a service
    24  	Delete(*Service) error
    25  	// List the managed services
    26  	List() ([]*Service, error)
    27  	// Start starts the runtime
    28  	Start() error
    29  	// Stop shuts down the runtime
    30  	Stop() error
    31  }
    32  
    33  // Notifier is an update notifier
    34  type Notifier interface {
    35  	// Notify publishes notification events
    36  	Notify() (<-chan Event, error)
    37  	// Close stops the notifier
    38  	Close() error
    39  }
    40  
    41  // EventType defines notification event
    42  type EventType int
    43  
    44  const (
    45  	// Create is emitted when a new build has been craeted
    46  	Create EventType = iota
    47  	// Update is emitted when a new update become available
    48  	Update
    49  	// Delete is emitted when a build has been deleted
    50  	Delete
    51  )
    52  
    53  // String returns human readable event type
    54  func (t EventType) String() string {
    55  	switch t {
    56  	case Create:
    57  		return "create"
    58  	case Delete:
    59  		return "delete"
    60  	case Update:
    61  		return "update"
    62  	default:
    63  		return "unknown"
    64  	}
    65  }
    66  
    67  // Event is notification event
    68  type Event struct {
    69  	// Type is event type
    70  	Type EventType
    71  	// Timestamp is event timestamp
    72  	Timestamp time.Time
    73  	// Service is the name of the service
    74  	Service string
    75  	// Version of the build
    76  	Version string
    77  }
    78  
    79  // Service is runtime service
    80  type Service struct {
    81  	// Name of the service
    82  	Name string
    83  	// Version of the service
    84  	Version string
    85  	// url location of source
    86  	Source string
    87  	// Metadata stores metadata
    88  	Metadata map[string]string
    89  }