From 8de6e69857a90408274fd8d6c3d0bdc24792fa0c Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Tue, 18 Dec 2018 10:21:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8EKeepalive=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=83=A8=E5=88=86.=E5=87=8F=E5=B0=91=E9=95=BF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pingworker.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pingworker.go b/pingworker.go index 5d902c9..edf04ac 100644 --- a/pingworker.go +++ b/pingworker.go @@ -2,9 +2,10 @@ package main import ( "log" - "net/http" "sync/atomic" "time" + + "474420502.top/eson/requests" ) // PingWorker 专为ping服务, 保证不存在多余的Ping的, 让终端服务的请求合理减少. @@ -23,11 +24,10 @@ func (pw *PingWorker) PingNet() bool { return atomic.LoadInt64(&pw.LastPingNet) == 1 } - timeout := time.Duration(5 * time.Second) - client := http.Client{ - Timeout: timeout, - } - _, err := client.Get("http://14.17.96.148:3333/ippool/switch/imactive") + ses := requests.NewSession() + ses.SetConfig(requests.CRequestTimeout, 5) + + _, err := ses.Get("http://14.17.96.148:3333/ippool/switch/imactive").Execute() if err != nil { log.Println("PingNet err http://14.17.96.148:3333/ippool/switch/imactive check Network") atomic.StoreInt64(&pw.LastPingNet, 0) @@ -46,11 +46,10 @@ func (pw *PingWorker) PingVPN() bool { return atomic.LoadInt64(&pw.LastPingVPN) == 1 } - timeout := time.Duration(5 * time.Second) - client := http.Client{ - Timeout: timeout, - } - _, err := client.Get("http://10.10.10.1:3333/ippool/switch/imactive") + ses := requests.NewSession() + ses.SetConfig(requests.CRequestTimeout, 5) + + _, err := ses.Get("http://10.10.10.1:3333/ippool/switch/imactive").Execute() if err != nil { log.Println("PingVPN err http://10.10.10.1:3333/ippool/switch/imactive check Network") atomic.StoreInt64(&pw.LastPingVPN, 0)