Add News widget and integrate NewsAPI for live updates
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"ArinDash/config"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
@@ -50,7 +49,7 @@ func (ph *PiHConnector) do(method string, endpoint string, body io.Reader) []byt
|
||||
req, err := http.NewRequest(method, requestString, body)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return make([]byte, 0)
|
||||
}
|
||||
|
||||
req.Header.Add("X-FTL-SID", ph.Session.SID)
|
||||
@@ -58,13 +57,13 @@ func (ph *PiHConnector) do(method string, endpoint string, body io.Reader) []byt
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return make([]byte, 0)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return make([]byte, 0)
|
||||
}
|
||||
|
||||
return respBody
|
||||
@@ -82,24 +81,24 @@ func Connect() PiHConnector {
|
||||
req, err := http.NewRequest("POST", "http://"+cfg.Pihole.Host+"/api/auth", strings.NewReader("{\"password\": \""+cfg.Pihole.Password+"\"}"))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := &PiHAuth{}
|
||||
|
||||
err = json.Unmarshal(respBody, s)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
connector = &PiHConnector{
|
||||
Host: cfg.Pihole.Host,
|
||||
|
||||
Reference in New Issue
Block a user