48 lines
696 B
Go
48 lines
696 B
Go
package cisa
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sync"
|
|
"time"
|
|
|
|
"istheinternetonfire.app/internal/config"
|
|
)
|
|
|
|
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
|
|
}
|
|
*/
|
|
|
|
d := GetExampleData()
|
|
|
|
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))
|
|
}
|
|
}
|