impl config State and config Interval
This commit is contained in:
@@ -1,7 +1,35 @@
|
||||
package config
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Interval Duration
|
||||
States []State
|
||||
}
|
||||
|
||||
var live Config
|
||||
|
||||
func Refresh() error {
|
||||
return errors.New("not impl")
|
||||
configPath, ok := os.LookupEnv("CONFIG")
|
||||
if !ok {
|
||||
configPath = "./config.json"
|
||||
}
|
||||
b, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var c Config
|
||||
if err := json.Unmarshal(b, &c); err != nil {
|
||||
return err
|
||||
}
|
||||
live = c
|
||||
return nil
|
||||
}
|
||||
|
||||
func Get() Config {
|
||||
return live
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user