consul

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

* 集成consul组件,包含实例化consul客户端,服务发现,服务注册,服务注销,负载均衡等方法

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *consulapi.Config

DefaultConfig 默认配置

func NewServiceCheck

func NewServiceCheck() *consulapi.AgentServiceCheck

NewServiceCheck 实例化服务检查项

func NewServiceRegistration

func NewServiceRegistration() *consulapi.AgentServiceRegistration

NewServiceRegistration 实例化服务注册项

Types

type Client

type Client struct {
	Config *consulapi.Config // 配置
	// contains filtered or unexported fields
}

Client 客户端

func (*Client) DeRegister

func (client *Client) DeRegister(name string) error

DeRegister 注销服务

func (*Client) Discover

func (client *Client) Discover(name string) ([]Service, error)

Discover 服务发现

func (*Client) Init

func (client *Client) Init() (err error)

NewClient 获取客户端

func (*Client) LoadBalance

func (client *Client) LoadBalance(serviceItems []Service) (*Service, error)

LoadBalance 负载均衡

func (*Client) Register

func (client *Client) Register(registration *consulapi.AgentServiceRegistration) error

Register 注册

type Service

type Service struct {
	// 服务ID
	ID string

	// 服务名称
	Name string

	// 服务地址
	Address string

	// 服务端口
	Port int

	// 服务标签
	Tags []string
}

Service 服务

func (*Service) GetHost

func (service *Service) GetHost() string

GetHost 获取服务完整的地址

Jump to

Keyboard shortcuts

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