discovery

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResponse

type CheckResponse struct {
	Url string

	RetryCount int
	// contains filtered or unexported fields
}

func (*CheckResponse) GetOnTime

func (r *CheckResponse) GetOnTime() int64

func (*CheckResponse) Result

func (r *CheckResponse) Result() string

func (*CheckResponse) SetHealthy

func (r *CheckResponse) SetHealthy(healthy string)

type Config

type Config struct {
	Id                 string
	Name               string
	RegisterAddr       string
	NodeAddr           map[string]string
	RegisterPort       int
	CheckAddr          string
	CheckPort          int
	Tags               []string
	IntervalTime       int // 健康检查间隔
	DeregisterTime     int //check失败后30秒删除本服务,注销时间,相当于过期时间
	TimeOut            int
	HttpRouter         HttpRouter
	CheckHealthyStatus bool
	CheckResponse      *CheckResponse
	CheckType          string // 检查类型 HTTP TCP GRPC
	CheckPath          string
	Token              string
	GrpcService        grpc.ServiceRegistrar
	Nodes              int
}

type DefaultServiceInstance

type DefaultServiceInstance struct {
	Id          string
	ServiceName string
	Host        string
	Port        uint64
	ClusterName string
	GroupName   string
	Tags        []string
	Enable      bool
	Healthy     bool
	Weight      float64
	Metadata    map[string]string
}

DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???

func (*DefaultServiceInstance) GetClusterName

func (d *DefaultServiceInstance) GetClusterName() string

func (*DefaultServiceInstance) GetGroupName

func (d *DefaultServiceInstance) GetGroupName() string

func (*DefaultServiceInstance) GetHost

func (d *DefaultServiceInstance) GetHost() string

GetHost will return the hostname

func (*DefaultServiceInstance) GetId

func (d *DefaultServiceInstance) GetId() string

GetId will return this instance's id. It should be unique.

func (*DefaultServiceInstance) GetMetadata

func (d *DefaultServiceInstance) GetMetadata() map[string]string

GetMetadata will return the metadata, it will never return nil

func (*DefaultServiceInstance) GetPort

func (d *DefaultServiceInstance) GetPort() uint64

GetPort will return the port.

func (*DefaultServiceInstance) GetServiceName

func (d *DefaultServiceInstance) GetServiceName() string

GetServiceName will return the serviceName

func (*DefaultServiceInstance) GetTags

func (d *DefaultServiceInstance) GetTags() []string

func (*DefaultServiceInstance) GetWeight

func (d *DefaultServiceInstance) GetWeight() float64

func (*DefaultServiceInstance) IsEnable

func (d *DefaultServiceInstance) IsEnable() bool

IsEnable will return the enable status of this instance

func (*DefaultServiceInstance) IsHealthy

func (d *DefaultServiceInstance) IsHealthy() bool

IsHealthy will return the value represent the instance whether healthy or not

type Discovery

type Discovery interface {
	Register() error
	Deregister() error
}

type HttpRouter

type HttpRouter func(r *CheckResponse)

type KV

type KV interface {
	Get(key string) ([]byte, error)
	Set(key string, value string) error
	Delete(key string) error
	List(key string) (map[string][]byte, error)
}

type Option

type Option func(*Config)

Option for queue system

func WithCheckAddr

func WithCheckAddr(addr string) Option

WithCheckAddr set addr function

func WithCheckGrpc

func WithCheckGrpc(s grpc.ServiceRegistrar) Option

WithCheckGrpc set checkHttp function r.GET(url, func(c *gin.Context) { c.String(200, "Healthy") })

func WithCheckHTTP

func WithCheckHTTP(router HttpRouter, checkHttp ...string) Option

WithCheckHTTP set checkHttp function r.GET(url, func(c *gin.Context) { c.String(200, "Healthy") })

func WithCheckPort

func WithCheckPort(port int) Option

WithCheckPort set port function

func WithCheckTCP

func WithCheckTCP() Option

WithCheckTCP set checkHttp function r.GET(url, func(c *gin.Context) { c.String(200, "Healthy") })

func WithCheckType

func WithCheckType(checkType string) Option

WithCheckType 检查类型 HTTP TCP GRPC

func WithDeregisterTime

func WithDeregisterTime(deregisterTime int) Option

WithDeregisterTime set deregisterTime function

func WithEnableHealthyStatus

func WithEnableHealthyStatus() Option

WithEnableHealthyStatus checkHealthyStatus function

func WithId

func WithId(id string) Option

WithId set id function

func WithIntervalTime

func WithIntervalTime(intervalTime int) Option

WithIntervalTime set intervalTime function

func WithName

func WithName(name string) Option

WithName set name function

func WithNodeAddr added in v0.0.2

func WithNodeAddr(val map[string]string) Option

WithNodeAddr set addr function

func WithRegisterAddr

func WithRegisterAddr(addr string) Option

WithRegisterAddr set addr function

func WithRegisterPort

func WithRegisterPort(port int) Option

WithRegisterPort set port function

func WithTags

func WithTags(tags ...string) Option

WithTags set tags function

func WithTimeOut

func WithTimeOut(timeOut int) Option

WithTimeOut set timeOut function

func WithToken

func WithToken(token string) Option

WithToken set WithToken token

type Service

type Service struct {
	Name     string            `json:"name"`
	Version  string            `json:"version"`
	Metadata map[string]string `json:"metadata"`
	Nodes    []ServiceInstance `json:"nodes"`
}

type ServiceInstance

type ServiceInstance interface {

	// GetId will return this instance's id. It should be unique.
	GetId() string

	// GetServiceName will return the serviceName
	GetServiceName() string

	// GetHost will return the hostname
	GetHost() string

	// GetPort will return the port.
	GetPort() uint64

	GetWeight() float64

	GetTags() []string

	GetClusterName() string

	GetGroupName() string

	// IsEnable will return the enable status of this instance
	IsEnable() bool

	// IsHealthy will return the value represent the instance whether healthy or not
	IsHealthy() bool

	// GetMetadata will return the metadata
	GetMetadata() map[string]string
}

ServiceInstance is the model class of an instance of a service, which is used for service registration and discovery.

Jump to

Keyboard shortcuts

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