initial commit
This commit is contained in:
45
internal/cisa/cisa.go
Normal file
45
internal/cisa/cisa.go
Normal 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))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user