sd

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultConsulAddr defaut consul addr
	DefaultConsulAddr = "http://127.0.0.1:8500"
	// DefaultCheckEndpoint default http check endpont
	DefaultCheckEndpoint = "/healthcheck"
)

Variables

This section is empty.

Functions

func InitServiceDiscovery

func InitServiceDiscovery(sdConfig *ServiceDiscoverySt, listenAddr string) (register SvcRegisteror, svc *SvcDef, err error)

InitServiceDiscovery init SD

Types

type ConsulRegisteror

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

ConsulRegisteror implements service registeror backed by Consul

func NewConsulRegisteror

func NewConsulRegisteror(addr string) *ConsulRegisteror

NewConsulRegisteror creates new ConsulRegisteror

func (ConsulRegisteror) Register

func (r ConsulRegisteror) Register(svc *SvcDef) (interface{}, error)

Register implements method of SvcRegisteror

func (ConsulRegisteror) Unregister

func (r ConsulRegisteror) Unregister(svc *SvcDef) (interface{}, error)

Unregister implements method of SvcRegisteror

type ServiceDiscoverySt

type ServiceDiscoverySt struct {
	Type          string `json:"type" yaml:"type"`
	RegAddr       string `json:"regaddr" yaml:"regaddr"`
	SvcName       string `json:"svcname" yaml:"svcname"`
	CheckEndpoint string `json:"check" yaml:"check"`
	CheckAddr     string `json:"checkaddr" yaml:"checkaddr"`
	DiscoveryInfo string `json:"discinfo" yaml:"discinfo"`
}

ServiceDiscoverySt defines config for consul discovery

type SvcDef

type SvcDef struct {
	Name        string
	ID          string
	Addr        string
	Port        int
	Tags        []string
	HealthCheck *SvcHealthChk
}

SvcDef defines a service to register

type SvcHealthChk

type SvcHealthChk struct {
	Type     string
	Content  string
	Interval int
	Timeout  int
}

SvcHealthChk defines health check of a service

type SvcRegisteror

type SvcRegisteror interface {
	Register(svc *SvcDef) (interface{}, error)
	Unregister(svc *SvcDef) (interface{}, error)
}

SvcRegisteror represents an interface for Service Discovery registration

Jump to

Keyboard shortcuts

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