config.go 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package util
  2. import (
  3. "github.com/sirupsen/logrus"
  4. "gopkg.in/yaml.v3"
  5. "lc-smartX/lc/model"
  6. "os"
  7. )
  8. var Config = func() config {
  9. var conf config
  10. file, err := os.ReadFile("./config.yaml")
  11. if err != nil {
  12. logrus.Fatal("配置文件读取失败! error:", err)
  13. }
  14. err = yaml.Unmarshal(file, &conf)
  15. if err != nil {
  16. logrus.Fatal("配置文件解析失败! error:", err)
  17. }
  18. return conf
  19. }()
  20. type config struct {
  21. HikServer hikServer `yaml:"hikServer"`
  22. Cameras []model.CameraInfo `yaml:"cameras"`
  23. Screens []model.ScreenInfo `yaml:"screens"`
  24. Server service `yaml:"service"`
  25. Mqtt MqttConfig `yaml:"mqtt"`
  26. }
  27. type MqttConfig struct {
  28. Server string `json:"server"`
  29. User string `json:"user"`
  30. Password string `json:"password"`
  31. Timeout uint `json:"timeout"`
  32. }
  33. type service struct {
  34. SupportCamera bool `yaml:"support_camera"`
  35. SupportLed bool `yaml:"support_led"`
  36. }
  37. type hikServer struct {
  38. Addr string `yaml:"addr"`
  39. Path string `yaml:"path"`
  40. }