Skip to content

Commit 083b2d9

Browse files
committed
make port configurable. Move server init to initalise func
1 parent faadd27 commit 083b2d9

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

config.yml.orig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Hardware:
2121
LEDType: "ws2801"
2222
# SPI bus frequency in Hz. 2097152 is a common, stable value for Raspberry Pi.
2323
SPIFrequency: 2097152
24+
# Port of the internal web server used for runtime configuration
25+
WebserverPort: 8080
2426

2527
# Configuration for the LED display output.
2628
Display:

config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type BlobCfg struct {
9292

9393
// HardwareConfig defines the hardware configuration.
9494
type HardwareConfig struct {
95+
WebserverPort uint16 `yaml:"WebserverPort"`
9596
LEDType string `yaml:"LEDType"`
9697
SPIFrequency int `yaml:"SPIFrequency"`
9798
Display DisplayConfig `yaml:"Display"`
@@ -261,4 +262,4 @@ func ReadConfig(cfile string) (*Config, error) {
261262

262263
slog.Debug("Read config", "config", conf)
263264
return &conf, nil
264-
}
265+
}

goleds.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@ func main() {
108108
reloadEvent := u.NewAtomicEvent[bool]()
109109
go watchConfigFile(*cfile, reloadEvent)
110110

111-
// Start the web server in a separate goroutine.
112-
http.Handle("/", http.FileServer(http.Dir("./web")))
113-
http.HandleFunc("/api/config", c.ConfigHandler(*cfile))
114-
go func() {
115-
slog.Info("Starting web server", "address", "http://localhost:8080")
116-
if err := http.ListenAndServe(":8080", nil); err != nil {
117-
slog.Error("Web server failed", "error", err)
118-
}
119-
}()
120-
121111
signal.Notify(ossignal, os.Interrupt)
122112

123113
for {
@@ -326,6 +316,17 @@ func (a *App) initialise(cfile string, realp bool, sensp bool) error {
326316

327317
go a.combineAndUpdateDisplay(ledReader, ledBufferPool)
328318
go a.stateManager()
319+
320+
// Start the web server in a separate goroutine.
321+
http.Handle("/", http.FileServer(http.Dir("./web")))
322+
http.HandleFunc("/api/config", c.ConfigHandler(cfile))
323+
go func() {
324+
slog.Info("Starting web server", "address", "http://localhost:8080")
325+
if err := http.ListenAndServe(fmt.Sprintf(":%d", conf.Hardware.WebserverPort), nil); err != nil {
326+
slog.Error("Web server failed", "error", err)
327+
}
328+
}()
329+
329330
return nil
330331
}
331332

0 commit comments

Comments
 (0)