func (h *HTTPCheck) Check() <-chan bool {
	return h.c
}
Check returns a call-back channel to give changes of health status immediately
package hc
import (
	"bytes"
	"context"
	"crypto/tls"
	"io"
	"io/ioutil"
	"net"
	"net/http"
	"sync"
	"time"
)
type HTTPCheckOptions struct {
	Path, HeaderHost             string
	Interval, Timeout            time.Duration
	FallThreshold, RiseThreshold int
	RespBody                     []byte
	UserAgent                    string
}
func (o *HTTPCheckOptions) CopyFrom(src *HTTPCheckOptions) {
	if src == nil {
		src = &HTTPCheckOptions{}
	}
	*o = *src
	if o.Path == "" {
		o.Path = "/"
	}
	if o.Path[0] != '/' {
		o.Path = "/" + o.Path
	}
	if o.Interval <= 0 {
		o.Interval = 10 * time.Second
	}
	if o.Timeout <= 0 {
		o.Timeout = 5 * time.Second
	}
	if o.FallThreshold <= 0 {
		o.FallThreshold = 3
	}
	if o.RiseThreshold <= 0 {
		o.RiseThreshold = 2
	}
	if src.RespBody != nil {
		o.RespBody = make([]byte, len(src.RespBody))
		copy(o.RespBody, src.RespBody)
	}
}
type HTTPCheck struct {
	server          string
	opts            HTTPCheckOptions
	client          *http.Client
	c               chan bool
	workerTmr       *time.Timer
	workerCtx       context.Context
	workerCtxCancel context.CancelFunc
	workerWg        sync.WaitGroup
	healthy         bool
	healthyMu       sync.RWMutex
	lastCheck       bool
	falls, rises    int
}
func NewHTTPCheck(server string, opts HTTPCheckOptions) (h *HTTPCheck) {
	h = &HTTPCheck{
		server: server,
	}
	h.opts.CopyFrom(&opts)
	h.client = &http.Client{
		Transport: &http.Transport{
			DialContext: (&net.Dialer{
				Timeout:   h.opts.Timeout,
				KeepAlive: h.opts.Timeout / 2,
				DualStack: true,
			}).DialContext,
			DisableKeepAlives:     true,
			TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
			TLSHandshakeTimeout:   h.opts.Timeout,
			ExpectContinueTimeout: 1 * time.Second,
		},
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return http.ErrUseLastResponse
		},
	}
	h.c = make(chan bool, 1)
	h.workerTmr = time.NewTimer(h.opts.Interval)
	h.workerCtx, h.workerCtxCancel = context.WithCancel(context.Background())
	h.workerWg.Add(1)
	go h.worker(h.workerCtx)
	return
}
func (h *HTTPCheck) Close() {
	h.workerTmr.Stop()
	h.workerCtxCancel()
	h.workerWg.Wait()
	h.healthyMu.Lock()
	h.healthy = false
	h.healthyMu.Unlock()
}
func (h *HTTPCheck) Healthy() bool {
	h.healthyMu.RLock()
	r := h.healthy
	h.healthyMu.RUnlock()
	return r
}