-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilites.go
56 lines (49 loc) · 1.09 KB
/
utilites.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"io"
"net/http"
"os"
"github.com/mattn/go-gtk/gtk"
)
func RunAlertMessage(parent *gtk.Window, format string) {
dialog := gtk.NewMessageDialog(parent, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, format)
dialog.Run()
dialog.Destroy()
}
func RunErrorMessage(parent *gtk.Window, format string) {
dialog := gtk.NewMessageDialog(parent, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, format)
dialog.Run()
dialog.Destroy()
}
func CheckFileNotExist(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return true
}
return false
}
func DownloadFile(url, filePath string) error {
file, err := os.Create(filePath)
if err != nil {
goline.LoggerPrintln(err)
return err
}
defer file.Close()
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
goline.LoggerPrintln(err)
return err
}
req.Header = *goline.client.GetHeader()
res, err := client.Do(req)
if err != nil {
goline.LoggerPrintln(err)
return err
}
defer res.Body.Close()
_, err = io.Copy(file, res.Body)
if err != nil {
goline.LoggerPrintln(err)
}
return err
}