mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 网络没有连通时记录日志
This commit is contained in:
parent
4d51ca3ad1
commit
c8ae0a360f
1 changed files with 11 additions and 5 deletions
|
|
@ -17,19 +17,20 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/88250/lute/ast"
|
|
||||||
"github.com/imroc/req/v3"
|
|
||||||
"github.com/siyuan-note/httpclient"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/88250/lute/ast"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/imroc/req/v3"
|
||||||
"github.com/olahol/melody"
|
"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)
|
c := req.C().SetTimeout(1 * time.Second)
|
||||||
resp, err := c.R().Head("https://www.baidu.com")
|
resp, err := c.R().Head("https://www.baidu.com")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -38,7 +39,12 @@ func IsOnline() bool {
|
||||||
resp, err = c.R().Head("https://api.ipify.org")
|
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 {
|
func GetRemoteAddr(session *melody.Session) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue