gomicro

package
v0.0.0-...-bb0ef8c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MulanPSL-2.0 Imports: 22 Imported by: 0

README

gomicro

基于micro/go-microv5.3.0版本改写的,consul基于v5/registry/consul/v1.0.2改写的,目录为plugins/v5/registry/consul/

依赖要求:github.com/hashicorp/consul/api原始为v1.9.0版本。

Documentation

Overview

addr provides functions to retrieve local IP addresses from device interfaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultVersion          = "latest"
	DefaultId               = uuid.New().String()
	DefaultRegisterTTL      = 2 * time.Second
	DefaultRegisterInterval = 1 * time.Second
)
View Source
var (
	// ErrIPNotFound no IP address found, and explicit IP not provided.
	ErrIPNotFound = errors.New("no IP address found, and explicit IP not provided")
)
View Source
var ErrNoneAvailable = errors.New("none available")

Functions

func HostPort

func HostPort(addr string, port interface{}) string

HostPort format addr and port suitable for dial.

Types

type ConsulOptions

type ConsulOptions struct {
	Addrs        []string             // 服务地址
	Timeout      time.Duration        // 超时时间
	Connect      bool                 // Connect specifies services should be registered as Consul Connect services.
	ConsulConfig *consul.Config       // API的配置信息
	DenyStale    bool                 // AllowStale sets whether any Consul server (non-leader) can service a read. This allows for lower latency and higher throughput at the cost of potentially stale data. Works similar to Consul DNS Config option [1]. Defaults to true. [1] https://www.consul.io/docs/agent/options.html#allow_stale
	QueryOptions *consul.QueryOptions // QueryOptions specifies the QueryOptions to be used when calling Consul. See `Consul API` for more information [1]. [1] https://godoc.org/github.com/hashicorp/consul/api#QueryOptions
	TCPCheck     time.Duration        // TCPCheck will tell the service provider to check the service address and port every `t` interval. It will enabled only if `t` is greater than 0. See `TCP + Interval` for more information [1]. [1] https://www.consul.io/docs/agent/checks.html
	/*
		=> protocol, port, httpEndpoint string, interval, timeout time.Duration
		consul.AgentServiceCheck{
			HTTP:     fmt.Sprintf("%s://{host}:%s%s", protocol, port, httpEndpoint),
			Interval: fmt.Sprintf("%v", interval),
			Timeout:  fmt.Sprintf("%v", timeout),
		}
	*/
	HTTPCheck *consul.AgentServiceCheck // HTTPCheck will tell the service provider to invoke the health check endpoint with an interval and timeout. It will be enabled only if interval and timeout are greater than 0. See `HTTP + Interval` for more information [1]. [1] https://www.consul.io/docs/agent/checks.html
}

type ConsulRegistry

type ConsulRegistry struct {
	Address []string // 服务地址
	// contains filtered or unexported fields
}

func NewConsulRegistry

func NewConsulRegistry(opts ConsulOptions) *ConsulRegistry

func (*ConsulRegistry) Client

func (c *ConsulRegistry) Client() *consul.Client

获取API连接,优先返回已有的连接

func (*ConsulRegistry) Deregister

func (c *ConsulRegistry) Deregister(s *RegistryService) error

func (*ConsulRegistry) GetService

func (c *ConsulRegistry) GetService(name string) ([]*RegistryService, error)

func (*ConsulRegistry) Register

func (c *ConsulRegistry) Register(s *RegistryService, ttl time.Duration) error

func (*ConsulRegistry) String

func (c *ConsulRegistry) String() string

type Logger

type Logger interface {
	Info(info string, fields ...interface{})
	Error(err error, info string, fields ...interface{})
	Fatal(err error, info string, fields ...interface{})
}
var DefaultLogger Logger = nil

[必须覆盖] 全局日志

type Next

type Next func() (*RegistryNode, error)

Next is a function that returns the next node based on the selector's strategy.

func Random

func Random(services []*RegistryService) Next

随机算法

func RoundRobin

func RoundRobin(services []*RegistryService) Next

轮询算法

type RegistryEndpoint

type RegistryEndpoint struct {
	Request  *RegistryValue    `json:"request"`
	Response *RegistryValue    `json:"response"`
	Metadata map[string]string `json:"metadata"`
	Name     string            `json:"name"`
}

type RegistryNode

type RegistryNode struct {
	Metadata map[string]string `json:"metadata"`
	Id       string            `json:"id"`
	Address  string            `json:"address"`
}

type RegistryService

type RegistryService struct {
	Name      string              `json:"name"`
	Version   string              `json:"version"`
	Metadata  map[string]string   `json:"metadata"`
	Endpoints []*RegistryEndpoint `json:"endpoints"`
	Nodes     []*RegistryNode     `json:"nodes"`
}

type RegistryValue

type RegistryValue struct {
	Name   string           `json:"name"`
	Type   string           `json:"type"`
	Values []*RegistryValue `json:"values"`
}

type WebOptions

type WebOptions struct {
	Name     string          // [必填] 服务名称
	Address  string          // [必填] 监听地址
	Handler  http.Handler    // [必填] 路由处理
	Registry *ConsulRegistry // [必填] 服务注册与发现
	// 以下为可选项
	Context          context.Context
	Metadata         map[string]string
	Version          string        // 服务版本号
	Id               string        // 服务实例ID,默认生成UUID
	RegisterInterval time.Duration // 注册间隔,大于0,默认2秒钟
	RegisterTTL      time.Duration // 默认1秒钟
}

type WebService

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

func NewWebService

func NewWebService(options WebOptions) *WebService

func (*WebService) Run

func (s *WebService) Run() error

Jump to

Keyboard shortcuts

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