mconsul

package
v0.0.0-...-0f09646 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDatacenter = NewDatacenter(discoverConfig.Datacenter)

默认为本地数据中心 - 一般局域网内只会访问本地的consul

Functions

func GetAddress

func GetAddress() string

func GetDatacenter

func GetDatacenter() string

func GetDatacenters

func GetDatacenters() ([]string, error)

func GetFromPrefix

func GetFromPrefix(key string) (map[string][]byte, error)

func GetNodeFromDC

func GetNodeFromDC(dc *Datacenter) (*api.CatalogNode, error)

func GetValue

func GetValue(key string) ([]byte, error)

func GetValueByAllDatacenter

func GetValueByAllDatacenter(key string) (string, error)

func PutValue

func PutValue(key string, value []byte) error

func SetAddress

func SetAddress(addr string)

Types

type Config

type Config struct {
	Datacenter string
	Address    string
	Token      string
}

type Datacenter

type Datacenter struct {
	Name string // 数据中心名称,第一个数据中心默认:dc1
	// contains filtered or unexported fields
}

func GetDefaultDatacenter

func GetDefaultDatacenter() *Datacenter

func NewDatacenter

func NewDatacenter(name string) *Datacenter

func (*Datacenter) DeleteKey

func (dc *Datacenter) DeleteKey(key string) error

从consul中删除key对应的value

func (*Datacenter) GetDatacenters

func (dc *Datacenter) GetDatacenters() ([]string, error)

https://www.consul.io/api-docs/catalog#list-datacenters 获取多数据中心

func (*Datacenter) GetNode

func (dc *Datacenter) GetNode() (*api.CatalogNode, error)

func (*Datacenter) GetPairs

func (dc *Datacenter) GetPairs(key string) ([]Pair, error)

func (*Datacenter) GetPairsFromPrefix

func (dc *Datacenter) GetPairsFromPrefix(prefix string) (map[string][]byte, error)

func (*Datacenter) GetPairsPrefix

func (dc *Datacenter) GetPairsPrefix(prefix string) (map[string]string, error)

func (*Datacenter) GetValue

func (dc *Datacenter) GetValue(key string) ([]byte, error)

根据key从数据中心中获取value

func (*Datacenter) PutValue

func (dc *Datacenter) PutValue(key string, value []byte) error

往consul中放入key - value

type Pair

type Pair struct {
	Key   string
	Value []byte
}

type Service

type Service struct {
	Name     string
	Method   []string
	LanAddr  string
	WanAddr  string
	NodeName string
	// contains filtered or unexported fields
}

func NewService

func NewService(name string, method []string) *Service

func (*Service) Deregister

func (s *Service) Deregister() error

deregister 注销服务

func (*Service) Register

func (s *Service) Register(port int, deregister bool, tags []string) error

注册 service 及其地址到 consul

Jump to

Keyboard shortcuts

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