Added internet check and warning when offline
This commit is contained in:
12
utils.go
12
utils.go
@@ -4,10 +4,12 @@ import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//Utilities
|
||||
@@ -91,3 +93,13 @@ func unzip(src, dest string) ([]string, error) {
|
||||
|
||||
return filenames, nil
|
||||
}
|
||||
|
||||
func hasInternet() bool {
|
||||
timeout := 2 * time.Second
|
||||
conn, err := net.DialTimeout("tcp", "8.8.8.8:53", timeout)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
conn.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user