Use time.Since to replace time.Now().Sub

This commit is contained in:
Star Brilliant committed 2018-11-27 20:18:30 +08:00
1 parent 35ddf43505
commit 95fe3e3b4e
1 file changed
+2 -2
+2 -2
View File
@@ -153,7 +153,7 @@ func NewClient(conf *config) (c *Client, err error) {
func (c *Client) newHTTPClient() error { func (c *Client) newHTTPClient() error {
c.httpClientMux.Lock() c.httpClientMux.Lock()
defer c.httpClientMux.Unlock() defer c.httpClientMux.Unlock()
if !c.httpClientLastCreate.IsZero() && time.Now().Sub(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second { if !c.httpClientLastCreate.IsZero() && time.Since(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second {
return nil return nil
} }
if c.httpTransport != nil { if c.httpTransport != nil {
@@ -220,7 +220,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.conf.Timeout)*time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.conf.Timeout)*time.Second)
defer cancel() defer cancel()
if r.Response == true { if r.Response {
log.Println("Received a response packet") log.Println("Received a response packet")
return return
} }