Support NATS cluster
This commit is contained in:
parent
d873538b70
commit
0b3d35721e
4 changed files with 11 additions and 9 deletions
|
@ -34,7 +34,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config
|
|||
defer display.Close()
|
||||
|
||||
// Controller
|
||||
ctrl := controllers.NewChamberController("Chamber 1", *config)
|
||||
ctrl := controllers.NewChamberController(*config)
|
||||
|
||||
// Configuration reload
|
||||
loadConfiguration := func() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -31,7 +32,9 @@ func main() {
|
|||
config := configuration.LoadConfiguration()
|
||||
|
||||
// NATS
|
||||
nc, err := nats.Connect(config.NATS.URL)
|
||||
servers := strings.Join(config.NATS.Servers, ",")
|
||||
userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password)
|
||||
nc, err := nats.Connect(servers, userInfo)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ import (
|
|||
|
||||
type Configuration struct {
|
||||
NATS struct {
|
||||
URL string `mapstructure:"url"`
|
||||
Servers []string `mapstructure:"servers"`
|
||||
Username string `mapstructure:"username"`
|
||||
Password string `mapstructure:"password"`
|
||||
Stream string `mapstructure:"stream"`
|
||||
Subject struct {
|
||||
Event string `mapstructure:"event"`
|
||||
|
|
|
@ -36,8 +36,6 @@ type ChamberController struct {
|
|||
C chan ChamberState
|
||||
isPaused bool
|
||||
|
||||
name string
|
||||
|
||||
// Current temperature readings.
|
||||
ambientTemperature float64
|
||||
chamberTemperature float64
|
||||
|
@ -50,10 +48,9 @@ type ChamberController struct {
|
|||
hub *sentry.Hub
|
||||
}
|
||||
|
||||
func NewChamberController(name string, config configuration.Configuration) *ChamberController {
|
||||
func NewChamberController(config configuration.Configuration) *ChamberController {
|
||||
return &ChamberController{
|
||||
C: make(chan ChamberState),
|
||||
name: name,
|
||||
config: config,
|
||||
pid: NewPIDController(config.PID.Kp, config.PID.Ki, config.PID.Kd),
|
||||
chTemp: make(chan temperature.TemperatureReading),
|
||||
|
|
Loading…
Reference in a new issue