Refactor configuration

This commit is contained in:
Søren Rasmussen 2022-03-15 17:20:47 +01:00
parent d28db0788f
commit 7adca39509
6 changed files with 11 additions and 11 deletions

View file

@ -24,7 +24,7 @@ import (
"github.com/spf13/viper"
)
func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config *configuration.ControllerConfig) {
func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config *configuration.Configuration) {
hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second)
defer wg.Done()

View file

@ -11,7 +11,7 @@ import (
)
type API struct {
config *configuration.ControllerConfig
config *configuration.Configuration
configChangeCallback func()
nc *nats.Conn
}

View file

@ -8,7 +8,7 @@ import (
"github.com/spf13/viper"
)
type ControllerConfig struct {
type Configuration struct {
NATS struct {
URL string `mapstructure:"url"`
Stream string `mapstructure:"stream"`
@ -49,7 +49,7 @@ type ControllerConfig struct {
} `mapstructure:"pid"`
}
func LoadConfiguration() *ControllerConfig {
func LoadConfiguration() *Configuration {
hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second)
@ -79,7 +79,7 @@ func LoadConfiguration() *ControllerConfig {
log.Printf("Error loading configuration: %v", err)
}
config := &ControllerConfig{}
config := &Configuration{}
if err := viper.Unmarshal(config); err != nil {
hub.CaptureException(err)
log.Fatal(err)

View file

@ -27,8 +27,8 @@ var ChamberStateMap = map[ChamberState]string{
}
type ChamberController struct {
ConfigUpdates chan configuration.ControllerConfig
config configuration.ControllerConfig
ConfigUpdates chan configuration.Configuration
config configuration.Configuration
// Current state.
chamberState ChamberState
@ -49,7 +49,7 @@ type ChamberController struct {
hub *sentry.Hub
}
func NewChamberController(name string, config configuration.ControllerConfig) *ChamberController {
func NewChamberController(name string, config configuration.Configuration) *ChamberController {
return &ChamberController{
C: make(chan ChamberState),
name: name,
@ -57,7 +57,7 @@ func NewChamberController(name string, config configuration.ControllerConfig) *C
pid: NewPIDController(config.PID.Kp, config.PID.Ki, config.PID.Kd),
chTemp: make(chan temperature.TemperatureReading),
chamberState: ChamberStateIdle,
ConfigUpdates: make(chan configuration.ControllerConfig, 1),
ConfigUpdates: make(chan configuration.Configuration, 1),
hub: sentry.CurrentHub().Clone(),
}
}

View file

@ -7,7 +7,7 @@ import (
"git.joco.dk/sng/fermentord/pkg/temperature"
)
func ReloadConfiguration(config *configuration.ControllerConfig, ctrl *ChamberController) {
func ReloadConfiguration(config *configuration.Configuration, ctrl *ChamberController) {
log.Printf("Reloading configuration")
temperature.ConfigUpdates <- []string{

View file

@ -34,7 +34,7 @@ func (p *DWIngest) AddState(state controllers.ChamberState) {
p.chState <- state
}
func (p *DWIngest) Run(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config *configuration.ControllerConfig) {
func (p *DWIngest) Run(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config *configuration.Configuration) {
hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second)
defer wg.Done()