initial commit

This commit is contained in:
2024-01-13 00:27:56 -06:00
parent 6d3a276bf0
commit 98efa97678
18 changed files with 1392 additions and 0 deletions

45
internal/cisa/cisa.go Normal file
View File

@@ -0,0 +1,45 @@
package cisa
import (
"encoding/json"
"net/http"
"sync"
"time"
"istheinternetonfire.app/internal/config"
"istheinternetonfire.app/internal/httpclient"
)
var (
mu sync.Mutex
Cisa CisaJSON
)
func Read() CisaJSON {
mu.Lock()
o := Cisa
mu.Unlock()
return o
}
func Start() {
for {
c := httpclient.NewClient(http.DefaultClient)
d, err := c.Get(config.Cfg.RemoteURL)
if err != nil {
time.Sleep(time.Second * 120)
continue
}
mu.Lock()
if err := json.Unmarshal(d, &Cisa); err != nil {
mu.Unlock()
time.Sleep(time.Second * 120)
continue
}
mu.Unlock()
config.Cfg.Log.Info("obtained remote data")
time.Sleep(time.Second * time.Duration(config.Cfg.RefreshSeconds))
}
}