generated from CubeCraft-Creations/Tracehound
CUB-181: Scaffold Go module, directory layout, config, and main.go entry point
This commit is contained in:
@@ -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
|
||||
}
|
||||
+24
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
// Package db provides SQLite database initialization and schema management.
|
||||
package db
|
||||
Reference in New Issue
Block a user