Documentation ¶
Index ¶
- Constants
- func ConvertStatusToString(status int32) string
- type Done
- type HTTP
- func (h *HTTP) Add(upstream string) error
- func (h *HTTP) AddBackup(upstream string) error
- func (h *HTTP) DoHealthCheck()
- func (h *HTTP) GetAvailableUpstream(index uint32) (upstream *HTTPUpstream)
- func (h *HTTP) GetAvailableUpstreamList() []*HTTPUpstream
- func (h *HTTP) GetUpstreamList() []*HTTPUpstream
- func (h *HTTP) Next(index ...uint32) (*HTTPUpstream, Done)
- func (h *HTTP) OnStatus(listener StatusListener)
- func (h *HTTP) PolicyFirst() *HTTPUpstream
- func (h *HTTP) PolicyLeastconn() *HTTPUpstream
- func (h *HTTP) PolicyRandom() *HTTPUpstream
- func (h *HTTP) PolicyRoundRobin() *HTTPUpstream
- func (h *HTTP) StartHealthCheck()
- func (h *HTTP) StopHealthCheck()
- type HTTPUpstream
- type StatusListener
Constants ¶
const ( // UpstreamUnknown upstream unknown UpstreamUnknown int32 = iota // UpstreamSick upstream sick UpstreamSick // UpstreamHealthy upstream healthy UpstreamHealthy // UpstreamIgnored upstream ignored UpstreamIgnored )
const ( // PolicyFirst get the first avaliable upstream PolicyFirst = "first" // PolicyRandom get random avaliable upstream PolicyRandom = "random" // PolicyRoundRobin get avaliable upstream round robin PolicyRoundRobin = "roundRobin" // PolicyLeastconn get least connection upstream PolicyLeastconn = "leastconn" )
const (
// UserAgent user agent for http check
UserAgent = "upstream/go"
)
Variables ¶
This section is empty.
Functions ¶
func ConvertStatusToString ¶
ConvertStatusToString convert status to string
Types ¶
type Done ¶ added in v0.0.4
type Done func()
Done done function for upstream it should be call when upstream is used done
type HTTP ¶
type HTTP struct { // Host the http host Host string // Ping http ping url Ping string // Timeout timeout for health check Timeout time.Duration // Interval health check interval Interval time.Duration // HealthCheckCount health check count HealthCheckCount int // MaxFailCount max fail count, if fail count >=, it will be set to sick MaxFailCount int // Policy upstream choose policy Policy string // contains filtered or unexported fields }
HTTP http upstream
func (*HTTP) GetAvailableUpstream ¶
func (h *HTTP) GetAvailableUpstream(index uint32) (upstream *HTTPUpstream)
GetAvailableUpstream get available upstream
func (*HTTP) GetAvailableUpstreamList ¶
func (h *HTTP) GetAvailableUpstreamList() []*HTTPUpstream
GetAvailableUpstreamList get available upstream list
func (*HTTP) GetUpstreamList ¶
func (h *HTTP) GetUpstreamList() []*HTTPUpstream
GetUpstreamList get all upstream
func (*HTTP) Next ¶ added in v0.0.4
func (h *HTTP) Next(index ...uint32) (*HTTPUpstream, Done)
Next get the next available upstream by policy
func (*HTTP) OnStatus ¶
func (h *HTTP) OnStatus(listener StatusListener)
OnStatus add listener for status event
func (*HTTP) PolicyFirst ¶
func (h *HTTP) PolicyFirst() *HTTPUpstream
PolicyFirst get the first backend
func (*HTTP) PolicyLeastconn ¶
func (h *HTTP) PolicyLeastconn() *HTTPUpstream
PolicyLeastconn get least connection backend
func (*HTTP) PolicyRandom ¶
func (h *HTTP) PolicyRandom() *HTTPUpstream
PolicyRandom get random backend
func (*HTTP) PolicyRoundRobin ¶
func (h *HTTP) PolicyRoundRobin() *HTTPUpstream
PolicyRoundRobin get backend round robin
func (*HTTP) StartHealthCheck ¶
func (h *HTTP) StartHealthCheck()
StartHealthCheck start health check
type HTTPUpstream ¶
type HTTPUpstream struct { // URL upstream url URL *url.URL // Backup backup upstream Backup bool // contains filtered or unexported fields }
HTTPUpstream http upstream
func (*HTTPUpstream) Healthy ¶
func (hu *HTTPUpstream) Healthy()
Healthy set the http upstream to be healthy
func (*HTTPUpstream) Ignored ¶
func (hu *HTTPUpstream) Ignored()
Ignored set the http upstream to be ignored
func (*HTTPUpstream) StatusDesc ¶ added in v0.0.2
func (hu *HTTPUpstream) StatusDesc() string
StatusDesc get upstream status description
type StatusListener ¶
type StatusListener func(status int32, upstream *HTTPUpstream)
StatusListener upstream status listener