From 3826741cf15933fdd0f7f27bea8ed8759717e615 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 Mar 2023 09:00:56 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=BD=91=E7=BB=9C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=BF=9E=E9=80=9A=E6=97=B6=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/net.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kernel/util/net.go b/kernel/util/net.go index fde90eae5..6a6ca030a 100644 --- a/kernel/util/net.go +++ b/kernel/util/net.go @@ -17,19 +17,20 @@ package util import ( - "github.com/88250/lute/ast" - "github.com/imroc/req/v3" - "github.com/siyuan-note/httpclient" "net/http" "strings" "time" "github.com/88250/gulu" + "github.com/88250/lute/ast" "github.com/gin-gonic/gin" + "github.com/imroc/req/v3" "github.com/olahol/melody" + "github.com/siyuan-note/httpclient" + "github.com/siyuan-note/logging" ) -func IsOnline() bool { +func IsOnline() (ret bool) { c := req.C().SetTimeout(1 * time.Second) resp, err := c.R().Head("https://www.baidu.com") if nil != err { @@ -38,7 +39,12 @@ func IsOnline() bool { resp, err = c.R().Head("https://api.ipify.org") } } - return nil == err && nil != resp && nil != resp.Response + + ret = nil == err && nil != resp && nil != resp.Response + if !ret { + logging.LogWarnf("network is offline") + } + return } func GetRemoteAddr(session *melody.Session) string {