-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-api.go
42 lines (36 loc) · 886 Bytes
/
admin-api.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
package main
import (
"net/http"
"os"
)
func notifyAdmin() {
var url = os.Getenv("ADMIN_NOTIFY_URL")
var token = os.Getenv("ADMIN_NOTIFY_TOKEN")
log.Info("Notifying the admin panel at " + url)
req, err := http.NewRequest("POST", url, nil)
if err != nil {
log.Errorw("Failed to notify the admin panel",
"error", err)
os.Exit(1)
}
req.Header.Set("Authorization", "Bearer "+token)
client := &http.Client{}
resp, err := client.Do(req)
defer func() {
if resp != nil {
resp.Body.Close()
}
}()
if err != nil {
log.Errorw("Failed to notify the admin panel", "error", err)
if resp != nil {
log.Errorw("Admin panel response status: ", "status", resp.Status)
}
os.Exit(1)
}
if resp != nil && resp.StatusCode != 200 {
log.Errorw("Failed to notify the admin panel", "status", resp.Status)
os.Exit(1)
}
log.Info("Admin panel has been notified")
}