discover

package
v0.0.0-...-bae3b6f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	DeregisterCriticalServiceAfter string   `json:"DeregisterCriticalServiceAfter"` // 多久之后注销服务
	Args                           []string `json:"Args,omitempty"`                 // 请求参数
	HTTP                           string   `json:"HTTP"`                           // 健康检查地址
	Interval                       string   `json:"Interval,omitempty"`             // Consul 主动检查间隔
	TTL                            string   `json:"TTL,omitempty"`                  // 服务实例主动维持心跳间隔,与Interval只存其一
}

type DiscoveryClient

type DiscoveryClient interface {

	/**
	 * 服务注册接口
	 * @param serviceName 服务名
	 * @param instanceId 服务实例Id
	 * @param instancePort 服务实例端口
	 * @param healthCheckUrl 健康检查地址
	 * @param instanceHost 服务实例地址
	 * @param meta 服务实例元数据
	 */
	Register(serviceName, instanceId, healthCheckUrl string, instanceHost string, instancePort int, meta map[string]string, logger *log.Logger) bool

	/**
	 * 服务注销接口
	 * @param instanceId 服务实例Id
	 */
	DeRegister(instanceId string, logger *log.Logger) bool

	/**
	 * 发现服务实例接口
	 * @param serviceName 服务名
	 */
	DiscoverServices(serviceName string, logger *log.Logger) []interface{}
}

func NewKitDiscoverClient

func NewKitDiscoverClient(consulHost string, consulPort int) (DiscoveryClient, error)

func NewMyDiscoverClient

func NewMyDiscoverClient(consulHost string, consulPort int) (DiscoveryClient, error)

type InstanceInfo

type InstanceInfo struct {
	ID                string                     `json:"ID"`                // 服务实例ID
	Service           string                     `json:"Service,omitempty"` // 服务发现时返回的服务名
	Name              string                     `json:"Name"`              // 服务名
	Tags              []string                   `json:"Tags,omitempty"`    // 标签,可用于进行服务过滤
	Address           string                     `json:"Address"`           // 服务实例HOST
	Port              int                        `json:"Port"`              // 服务实例端口
	Meta              map[string]string          `json:"Meta,omitempty"`    // 元数据
	EnableTagOverride bool                       `json:"EnableTagOverride"` // 是否允许标签覆盖
	Check             `json:"Check,omitempty"`   // 健康检查相关配置
	Weights           `json:"Weights,omitempty"` // 权重
}

服务实例结构体

type KitDiscoverClient

type KitDiscoverClient struct {
	Host string // Consul Host
	Port int    // Consul Port
	// contains filtered or unexported fields
}

func (*KitDiscoverClient) DeRegister

func (consulClient *KitDiscoverClient) DeRegister(instanceId string, logger *log.Logger) bool

func (*KitDiscoverClient) DiscoverServices

func (consulClient *KitDiscoverClient) DiscoverServices(serviceName string, logger *log.Logger) []interface{}

func (*KitDiscoverClient) Register

func (consulClient *KitDiscoverClient) Register(serviceName, instanceId, healthCheckUrl string, instanceHost string, instancePort int, meta map[string]string, logger *log.Logger) bool

type MyDiscoverClient

type MyDiscoverClient struct {
	Host string // Consul 的 Host
	Port int    // Consul 的 端口
}

func (*MyDiscoverClient) DeRegister

func (consulClient *MyDiscoverClient) DeRegister(instanceId string, logger *log.Logger) bool

func (*MyDiscoverClient) DiscoverServices

func (consulClient *MyDiscoverClient) DiscoverServices(serviceName string, logger *log.Logger) []interface{}

func (*MyDiscoverClient) Register

func (consulClient *MyDiscoverClient) Register(serviceName, instanceId, healthCheckUrl string, instanceHost string, instancePort int, meta map[string]string, logger *log.Logger) bool

type Weights

type Weights struct {
	Passing int `json:"Passing"`
	Warning int `json:"Warning"`
}

Jump to

Keyboard shortcuts

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