discover

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartDiscoverServer

func StartDiscoverServer(addr string, udd time.Duration, drd time.Duration)

Types

type GUID

type GUID uint64

type HeartbeatInfo

type HeartbeatInfo struct {
	CPUUse      uint `json:"cpu_use"`
	MemoryTotal uint `json:"memory_total"`
	MemoryUsed  uint `json:"memory_used"`
}

type InstanceManager

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

The instance of current micro-service, nil if not registered

func (*InstanceManager) FetchInstanceInfo

func (InstanceManager *InstanceManager) FetchInstanceInfo()

func (*InstanceManager) Register

func (InstanceManager *InstanceManager) Register(service *MicroService, remoteAddr string, heartbeatDuration time.Duration)

func (*InstanceManager) Unregister

func (InstanceManager *InstanceManager) Unregister()

unregister service when exit

type MicroService

type MicroService struct {
	InstanceId    GUID          `json:"instance_id"`
	RegisterTime  time.Time     `json:"register_time"`
	LastHeartbeat time.Time     `json:"last_heartbeat"`
	Status        ServiceStatus `json:"status"`

	Address     string `json:"address"`
	Port        uint   `json:"port"`
	ServiceName string `json:"service_name"`
	Weight      uint   `json:"weight"`

	CPUUse      uint `json:"cpu_use"`
	MemoryTotal uint `json:"memory_total"`
	MemoryUsed  uint `json:"memory_used"`
}

func NewMicroService

func NewMicroService(serviceName string, port uint) *MicroService

func NewWeightedMicroService

func NewWeightedMicroService(serviceName string, port uint, serviceWeigh uint) *MicroService

type RegisterRequest

type RegisterRequest struct {
	ServiceName string `json:"service_name"`
	Weight      uint   `json:"weight"`
	Port        uint   `json:"port"`
	CPUUse      uint   `json:"cpu_use"`
	MemoryTotal uint   `json:"memory_total"`
	MemoryUsed  uint   `json:"memory_used"`
}

type RegisterServer

type RegisterServer struct {
	sync.Mutex
	ServiceInstances
	UpToDownDuration     time.Duration
	DownToRemoveDuration time.Duration
	// contains filtered or unexported fields
}

type RegisteredInfo

type RegisteredInfo struct {
	InstanceId   GUID          `json:"instance_id"`
	RegisterTime time.Time     `json:"register_time"`
	Status       ServiceStatus `json:"status"`
}

type RestClient

type RestClient struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

RestClient is the recommended approach to do rest request in server

func NewRestClient

func NewRestClient(timeout time.Duration, service *MicroService) *RestClient

func (*RestClient) Do

func (s *RestClient) Do(r *http.Request) (*http.Response, error)

type RestRequester

type RestRequester interface {
	Do(r *http.Request) (*http.Response, error)
}

type ServiceInfo

type ServiceInfo struct {
	ServiceName string `json:"service_name"`
	Guid        GUID   `json:"guid"`
}

type ServiceInstances

type ServiceInstances struct {
	Instance map[string][]MicroService `json:"instance"`
	Version  uint64                    `json:"version"`
}

type ServiceStatus

type ServiceStatus int
const (
	Up ServiceStatus
	Exhausted
	Down
)

Jump to

Keyboard shortcuts

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