client

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 11 Imported by: 2

README

radar-go-client

This is the go version of radar client.

TODO

  • currently, all of the parameters below are hardcode
    • bufferSize: the receive buffer size of the connection to radar server
    • radarServerTimeout: when is radar server to be considered connection lost
    • heartBeatInterval: the interval of heartbeat check
    • dialTimeout: the timeout value of dialing to radar server
  • "action": this is the key word in transport protocol, but find no specific definition
  • protocal extension
    • only support heartbeat/getAppMethod/watchAppStatus methods right now
  • update Version and Date manually right now, need a proper way to track changes

Documentation

Index

Constants

View Source
const (
	VERSION = "(moooofly)"
	DATE    = "20200223"
)

Variables

View Source
var (
	// ErrRadarServerLost shows the connection lost err
	ErrRadarServerLost = errors.New("radar server lost")

	// ErrRadarClientStopped shows the client has been stopped
	ErrRadarClientStopped = errors.New("radar client stopped")
)

Functions

This section is empty.

Types

type AppControl

type AppControl uint8

AppControl represent the state of an app whether is enabled

const (

	// AppDisabled shows the app is disabled
	AppDisabled AppControl = 0

	// AppEnabled shows the app is enabled
	AppEnabled AppControl = 1
)

func (AppControl) String

func (s AppControl) String() string

String return the string of app status

type AppStatus

type AppStatus uint8

AppStatus represent the status of an app

const (

	// AppStatusRunning shows the app is running
	AppStatusRunning AppStatus = 0

	// AppStatusFailed shows the app has failed
	AppStatusFailed AppStatus = 1
)

func (AppStatus) String

func (s AppStatus) String() string

String return the string of app status

type ControlRsp

type ControlRsp struct {
	RspComm
	Control AppControl
}

ControlRsp is used by GetAppControl()

type EventReq

type EventReq uint8

EventReq is the event which happened

const (

	// AppStatusEventCreated shows the app has been registered in radar server
	AppStatusEventCreated EventReq = 1

	// AppStatusEventDeleted shows the app has been de-registered in radar server
	AppStatusEventDeleted EventReq = 2

	// AppStatusEventChanged shows the app status has been changed
	AppStatusEventChanged EventReq = 3
)

type EventRsp

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

EventRsp is returned by radar watch API, which will be passed into callback

type RadarClient

type RadarClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RadarClient represent a radar client

func NewRadarClient

func NewRadarClient(ip, port string, logger *logrus.Logger) *RadarClient

NewRadarClient returns a instance of radar client

func (*RadarClient) Connect

func (rc *RadarClient) Connect() error

Connect tries to connect with radar server This API will not return until the REAL connection has been established

func (*RadarClient) Connected

func (rc *RadarClient) Connected() bool

Connected returns the current connection state

func (*RadarClient) Disconnect

func (rc *RadarClient) Disconnect()

Disconnect the client, together will connection will radar server

func (*RadarClient) GetAppControl

func (rc *RadarClient) GetAppControl(args []ReqArgs) ([]ControlRsp, error)

GetAppControl returns the app control state

func (*RadarClient) GetAppStatus

func (rc *RadarClient) GetAppStatus(args []ReqArgs) ([]StatusRsp, error)

GetAppStatus returns the app status

func (*RadarClient) SetAppControl

func (rc *RadarClient) SetAppControl(operation, domainMoid, resourceMoid, groupMoid, serverMoid, serverName string) (bool, error)

NOTE: resourceMoid is equal to machineRoomMoid SetAppControl

func (*RadarClient) Version

func (rc *RadarClient) Version() string

Version returns the current radar client version

func (*RadarClient) WatchAppStatus

func (rc *RadarClient) WatchAppStatus(args ReqArgs, cb func(rpl EventRsp, err error)) error

WatchAppStatus watches the specific app status

type ReqArgs

type ReqArgs struct {
	DomainMoid   string `json:"domain_moid"`
	ResourceMoid string `json:"resource_moid"`
	GroupMoid    string `json:"group_moid"`
	ServerMoid   string `json:"server_moid"`
	ServerName   string `json:"server_name"`
}

ReqArgs is the common request args which is set into client API

type RspComm

type RspComm struct {
	ServerMoid string
	ServerName string
}

type StatusRsp

type StatusRsp struct {
	RspComm
	Status AppStatus
}

StatusRsp is used by GetAppStatus()

Jump to

Keyboard shortcuts

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