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
}

View File

@@ -7,9 +7,56 @@ import (
type State string
var States = map[int]State{
27006: "NC",
84058: "UT",
var States = map[string]State{
"99654": "AL",
"72401": "AR",
"85364": "AZ",
"90011": "CA",
"80013": "CO",
"06902": "CT",
"19720": "DE",
"33024": "FL",
"30043": "GA",
"96706": "HI",
"50613": "IA",
"83646": "ID",
"60629": "IL",
"47906": "IN",
"66062": "KS",
"40475": "KY",
"70726": "LA",
"02301": "MA",
"20906": "MD",
"04401": "ME",
"48197": "MI",
"55106": "MN",
"63376": "MO",
"39503": "MS",
"59901": "MT",
"27006": "NC",
"58103": "ND",
"68516": "NE",
"03103": "NH",
"08701": "NJ",
"87121": "NM",
"89108": "NV",
"11368": "NY",
"45011": "OH",
"73099": "OK",
"97006": "OR",
"19120": "PA",
"02860": "RI",
"29483": "SC",
"57106": "SD",
"37013": "TN",
"77449": "TX",
"84058": "UT",
"22193": "VA",
"05401": "VT",
"99301": "WA",
"53215": "WI",
"26554": "WV",
"82001": "WY",
}
func (state *State) UnmarshalJSON(b []byte) error {