From 69b050b62b256673b7f0f0b67fb0e6b2b338850a Mon Sep 17 00:00:00 2001 From: Joshua Date: Mon, 18 May 2026 17:40:23 -0400 Subject: [PATCH] CUB-181: Scaffold Go module, directory layout, config, and main.go entry point --- cmd/server/main.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++ config.yaml | 24 +++++++++++++++ go.mod | 3 ++ internal/db/db.go | 2 ++ 4 files changed, 104 insertions(+) create mode 100644 cmd/server/main.go create mode 100644 config.yaml create mode 100644 go.mod create mode 100644 internal/db/db.go diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..61803f1 --- /dev/null +++ b/cmd/server/main.go @@ -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 +} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..2058275 --- /dev/null +++ b/config.yaml @@ -0,0 +1,24 @@ +# RemoteRig Central Hub Configuration +# Target platform: Raspberry Pi Zero 2 W + +# Database +db_path: "remoterig.db" + +# API Key for endpoint authentication +api_key: "changeme" + +# Server settings +port: 8080 +read_timeout: 5s +write_timeout: 10s +idle_timeout: 120s + +# MQTT Broker +mqtt: + broker: "localhost:1883" + client_id: "remoterig-hub" + +# Platform +platform: + type: "pi-zero-2w" + max_cameras: 16 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cc54a5c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/cubecraft/remoterig + +go 1.24.2 diff --git a/internal/db/db.go b/internal/db/db.go new file mode 100644 index 0000000..f9e2c3e --- /dev/null +++ b/internal/db/db.go @@ -0,0 +1,2 @@ +// Package db provides SQLite database initialization and schema management. +package db