All checks were successful
Dev Build / build-test (pull_request) Successful in 1m29s
- Moonraker REST client with GetPrinterInfo, GetPrintStats, GetPrintHistory - Moonraker WebSocket client with auto-reconnect + telemetry parsing - MQTT client via paho.mqtt.golang with TLS support for Bambu Lab - Moonraker poller worker: background polling, dedup, usage logging to PostgreSQL - MQTT subscriber worker: Bambu telemetry parsing, print job tracking - Config: 7 new env vars (MOONRAKER_URL, MQTT_BROKER, etc.) - main.go: per-printer worker discovery, graceful shutdown
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
)
|
|
|
|
// Config holds all application configuration loaded from environment variables.
|
|
type Config struct {
|
|
DatabaseURL string `envconfig:"database_url" required:"true"`
|
|
Port string `envconfig:"port" default:"8080"`
|
|
CorsOrigin string `envconfig:"cors_origin" default:"*"`
|
|
LogLevel string `envconfig:"log_level" default:"info"`
|
|
|
|
// Moonraker integration.
|
|
MoonrakerURL string `envconfig:"moonraker_url" default:"http://localhost:7125"`
|
|
MoonrakerPollInterval string `envconfig:"moonraker_poll_interval" default:"10s"`
|
|
|
|
// MQTT (Bambu Lab) integration.
|
|
MQTTBroker string `envconfig:"mqtt_broker" default:"localhost:1883"`
|
|
MQTTTopicPrefix string `envconfig:"mqtt_topic_prefix" default:"device/+/report"`
|
|
MQTTClientID string `envconfig:"mqtt_client_id" default:"extrudex"`
|
|
MQTTTLSCert string `envconfig:"mqtt_tls_cert" default:""`
|
|
MQTTTLSKey string `envconfig:"mqtt_tls_key" default:""`
|
|
}
|
|
|
|
// Load reads configuration from environment variables and returns a populated Config.
|
|
func Load() (*Config, error) {
|
|
var cfg Config
|
|
if err := envconfig.Process("", &cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to load config: %w", err)
|
|
}
|
|
return &cfg, nil
|
|
}
|