registry

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 6 Imported by: 0

README

xxx

介绍
  1. xxxx
  2. xxxx
  3. xxxx
安装教程

go get github.com/jageros/hawox

使用例子
package main

import (
	"fmt"
	"github.com/jageros/hawox/xxx"
)

func main() {
	/*
	xxxxx
	xxxxx
	xxxxx
	*/
}
使用说明
  1. xxxx
  2. xxxx
  3. xxxx

Documentation

Index

Constants

View Source
const Prefix = "/microservices"

Variables

This section is empty.

Functions

This section is empty.

Types

type Discovery

type Discovery interface {
	// GetService return the service instances in memory according to the service name.
	GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
	// Watch creates a watcher according to the service name.
	Watch(ctx context.Context, serviceName string) (Watcher, error)
}

Discovery is service discovery.

type Option

type Option func(o *options)

Option is etcd registry option.

func Context

func Context(ctx context.Context) Option

Context with registry context.

func Namespace

func Namespace(ns string) Option

Namespace with registry namespance.

func RegisterTTL

func RegisterTTL(ttl time.Duration) Option

RegisterTTL with register ttl.

type Registrar

type Registrar interface {
	// Register the registration.
	Register(ctx context.Context, service *ServiceInstance) error
	// Deregister the registration.
	Deregister(ctx context.Context, service *ServiceInstance) error
}

Registrar is service registrar.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is etcd registry.

func New

func New(client *clientv3.Client, opts ...Option) (r *Registry)

New creates etcd registry

func (*Registry) Deregister

func (r *Registry) Deregister(ctx context.Context, service *ServiceInstance) error

Deregister the registration.

func (*Registry) GetService

func (r *Registry) GetService(ctx context.Context, name string) ([]*ServiceInstance, error)

GetService return the service instances in memory according to the service name.

func (*Registry) Register

func (r *Registry) Register(ctx context.Context, service *ServiceInstance) error

Register the registration.

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, name string) (Watcher, error)

Watch creates a watcher according to the service name.

type ServiceInstance

type ServiceInstance struct {
	// ID is the unique instance ID as registered.
	ID string `json:"id"`
	// Name is the service name as registered.
	Name string `json:"name"`
	// Type is the service Type as registered
	// schema:
	//    http
	//    rpc
	//    websocket
	Type string
	// Version is the version of the compiled.
	Version string `json:"version"`
	// Metadata is the kv pair metadata associated with the service instance.
	Metadata map[string]string `json:"metadata"`
	// Endpoints is endpoint addresses of the service instance.
	// schema:
	//   127.0.0.1:8000
	Endpoint string `json:"endpoints"`
}

ServiceInstance is an instance of a service in a discovery system.

func (*ServiceInstance) Key

func (s *ServiceInstance) Key(namespace string) string

type Watcher

type Watcher interface {
	// Next returns services in the following two cases:
	// 1.the first time to watch and the service instance list is not empty.
	// 2.any service instance changes found.
	// if the above two conditions are not met, it will block until context deadline exceeded or canceled
	Next() ([]*ServiceInstance, error)
	// Stop close the watcher.
	Stop() error
}

Watcher is service watcher.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL