Documentation ¶
Overview ¶
addr provides functions to retrieve local IP addresses from device interfaces.
Index ¶
- Variables
- func HostPort(addr string, port interface{}) string
- type ConsulOptions
- type ConsulRegistry
- func (c *ConsulRegistry) Client() *consul.Client
- func (c *ConsulRegistry) Deregister(s *RegistryService) error
- func (c *ConsulRegistry) GetService(name string) ([]*RegistryService, error)
- func (c *ConsulRegistry) Register(s *RegistryService, ttl time.Duration) error
- func (c *ConsulRegistry) String() string
- type Logger
- type Next
- type RegistryEndpoint
- type RegistryNode
- type RegistryService
- type RegistryValue
- type WebOptions
- type WebService
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 ¶
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) 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 Next ¶
type Next func() (*RegistryNode, error)
Next is a function that returns the next node based on the selector's strategy.
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 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
Click to show internal directories.
Click to hide internal directories.