Nits
This commit is contained in:
parent
a26b2b42f0
commit
70970d2333
|
@ -82,7 +82,7 @@ func ParseIP(ipStr string) net.IP {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If ttl < 0, never expire
|
// If ttl < 0, never expire
|
||||||
// ttl is set always at least xTransport.timeout otherwise
|
// Otherwise, ttl is set to max(ttl, xTransport.timeout)
|
||||||
func (xTransport *XTransport) saveCachedIP(host string, ip net.IP, ttl time.Duration) {
|
func (xTransport *XTransport) saveCachedIP(host string, ip net.IP, ttl time.Duration) {
|
||||||
xTransport.cachedIPs.Lock()
|
xTransport.cachedIPs.Lock()
|
||||||
item := &CachedIPItem{ip: ip, ttl: time.Time{}}
|
item := &CachedIPItem{ip: ip, ttl: time.Time{}}
|
||||||
|
@ -96,15 +96,14 @@ func (xTransport *XTransport) saveCachedIP(host string, ip net.IP, ttl time.Dura
|
||||||
xTransport.cachedIPs.Unlock()
|
xTransport.cachedIPs.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If expire is true, remove data if expired
|
func (xTransport *XTransport) loadCachedIP(host string, deleteIfExpired bool) (net.IP, bool) {
|
||||||
func (xTransport *XTransport) loadCachedIP(host string, expire bool) (net.IP, bool) {
|
|
||||||
xTransport.cachedIPs.Lock()
|
xTransport.cachedIPs.Lock()
|
||||||
defer xTransport.cachedIPs.Unlock()
|
defer xTransport.cachedIPs.Unlock()
|
||||||
item, ok := xTransport.cachedIPs.cache[host]
|
item, ok := xTransport.cachedIPs.cache[host]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if expire && !item.ttl.IsZero() && time.Until(item.ttl) < 0 {
|
if deleteIfExpired && !item.ttl.IsZero() && time.Until(item.ttl) < 0 {
|
||||||
delete(xTransport.cachedIPs.cache, host)
|
delete(xTransport.cachedIPs.cache, host)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue