func NewMonitor(r *database.Redis, c *mirrors.Cache) *Monitor { monitor := new(Monitor) monitor.redis = r monitor.cache = c monitor.cluster = NewCluster(r) monitor.mirrors = make(map[string]*Mirror) monitor.healthCheckChan = make(chan string, healthCheckThreads*5) monitor.syncChan = make(chan string) monitor.stop = make(chan bool) monitor.configNotifier = make(chan bool, 1) SubscribeConfig(monitor.configNotifier) rand.Seed(time.Now().UnixNano()) monitor.httpTransport = http.Transport{ DisableKeepAlives: true, MaxIdleConnsPerHost: 0, Dial: func(network, addr string) (net.Conn, error) { deadline := time.Now().Add(clientDeadline) c, err := net.DialTimeout(network, addr, clientTimeout) if err != nil { return nil, err } c.SetDeadline(deadline) return c, nil }, } monitor.httpClient = http.Client{ CheckRedirect: checkRedirect, Transport: &monitor.httpTransport, } return monitor }