CUB-181: Scaffold Go module, directory layout, config, and main.go entry point

This commit is contained in:
2026-05-18 17:40:23 -04:00
parent 58a5d9e97a
commit 69b050b62b
4 changed files with 104 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
// Package main is the entry point for the RemoteRig central hub.
package main
import (
"fmt"
"log"
"os"
"time"
"gopkg.in/yaml.v3"
)
// Config holds the application configuration.
type Config struct {
DBPath string `yaml:"db_path"`
APIKey string `yaml:"api_key"`
Port string `yaml:"port"`
ReadTimeout time.Duration `yaml:"read_timeout"`
WriteTimeout time.Duration `yaml:"write_timeout"`
IdleTimeout time.Duration `yaml:"idle_timeout"`
MQTT struct {
Broker string `yaml:"broker"`
ClientID string `yaml:"client_id"`
} `yaml:"mqtt"`
Platform struct {
Type string `yaml:"type"`
MaxCameras int `yaml:"max_cameras"`
} `yaml:"platform"`
}
func main() {
log.Println("RemoteRig hub starting...")
// Load config
cfg, err := loadConfig("config.yaml")
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
// Print config
log.Printf("Database: %s", cfg.DBPath)
log.Printf("API key set: %t", cfg.APIKey != "")
log.Printf("Server port: %s", cfg.Port)
log.Printf("MQTT broker: %s", cfg.MQTT.Broker)
log.Printf("Platform: %s (max %d cameras)", cfg.Platform.Type, cfg.Platform.MaxCameras)
log.Println("RemoteRig hub ready")
}
func loadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read config file: %w", err)
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config: %w", err)
}
if cfg.Port == "" {
cfg.Port = "8080"
}
if cfg.DBPath == "" {
cfg.DBPath = "remoterig.db"
}
if cfg.MQTT.Broker == "" {
cfg.MQTT.Broker = "localhost:1883"
}
if cfg.MQTT.ClientID == "" {
cfg.MQTT.ClientID = "remoterig-hub"
}
return &cfg, nil
}