Files
AI-tianyan/internal/config/config.go

46 lines
1.0 KiB
Go
Raw Normal View History

package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
EdgeID string `yaml:"edge_id"`
CloudURL string `yaml:"cloud_url"`
EdgeToken string `yaml:"edge_token"`
RTSPURLs []string `yaml:"rtsp_urls"`
InferSocket string `yaml:"infer_socket"`
InferFPS int `yaml:"infer_fps"`
InferWorkers int `yaml:"infer_workers"`
ConfThreshold float64 `yaml:"conf_threshold"`
DedupWindowSec int `yaml:"dedup_window_sec"`
Version string `yaml:"version"`
}
func Load(path string) *Config {
cfg := &Config{
EdgeID: "edge-demo-001",
CloudURL: "http://localhost:8004",
InferSocket: "/tmp/edge-infer.sock",
InferFPS: 5,
InferWorkers: 2,
ConfThreshold: 0.5,
DedupWindowSec: 30,
Version: "1.0.0",
}
data, err := os.ReadFile(path)
if err != nil {
return cfg
}
_ = yaml.Unmarshal(data, cfg)
if cfg.InferWorkers <= 0 {
cfg.InferWorkers = 1
}
if cfg.DedupWindowSec <= 0 {
cfg.DedupWindowSec = 30
}
return cfg
}