impl stubbed out scrape and push

This commit is contained in:
Bel LaPointe
2022-01-09 22:28:03 -05:00
parent ad9af0a5db
commit 37c66244df
9 changed files with 453 additions and 19 deletions

View File

@@ -3,12 +3,18 @@ package config
import (
"encoding/json"
"io/ioutil"
"local/storage"
"os"
"sync"
)
type Config struct {
Interval Duration
States []State
Storage []string
lock sync.Mutex
db storage.DB
}
var live Config
@@ -30,6 +36,24 @@ func Refresh() error {
return nil
}
func Get() Config {
return live
func Get() *Config {
return &live
}
func (c *Config) DB() storage.DB {
if c.db == nil {
c.lock.Lock()
defer c.lock.Unlock()
if c.db == nil {
if len(c.Storage) == 0 {
c.Storage = []string{storage.MAP.String()}
}
db, err := storage.New(storage.TypeFromString(c.Storage[0]), c.Storage[1:]...)
if err != nil {
panic(err)
}
c.db = db
}
}
return c.db
}