package loadbalance import ( "net/http" "time" ) // Return the last ping status to see if the target is online func (m *RouteManager) IsTargetOnline(matchingDomainOrIp string) bool { value, ok := m.LoadBalanceMap.Load(matchingDomainOrIp) if !ok { return false } isOnline, ok := value.(bool) return ok && isOnline } // Ping a target to see if it is online func PingTarget(target *PrimaryRoutingRule) bool { client := &http.Client{ Timeout: 10 * time.Second, } url := target.MatchingDomainOrIp if target.RequireTLS { url = "https://" + url } else { url = "http://" + url } resp, err := client.Get(url) if err != nil { return false } defer resp.Body.Close() return resp.StatusCode == http.StatusOK }