config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package global
  2. import (
  3. "log"
  4. "github.com/BurntSushi/toml"
  5. )
  6. type Config struct {
  7. Database DatabaseConfig `toml:"database"`
  8. App AppConfig `toml:"config"`
  9. Logs LogConfig `toml:"logs"`
  10. }
  11. type AppConfig struct {
  12. Ip string `toml:"ip"`
  13. Port string `toml:"port"`
  14. IsGenerate bool `toml:"is_generate"`
  15. }
  16. type DatabaseConfig struct {
  17. OADBIP string `toml:"oadb_ip"`
  18. OADBPort string `toml:"oadb_port"`
  19. OADBDb string `toml:"oadb_db"`
  20. OADBUser string `toml:"oadb_user"`
  21. OADBPass string `toml:"oadb_password"`
  22. LicDBIP string `toml:"licdb_ip"`
  23. LicDBPort string `toml:"licdb_port"`
  24. LicDBDb string `toml:"licdb_db"`
  25. LicDBUser string `toml:"licdb_user"`
  26. LicDBPass string `toml:"licdb_password"`
  27. }
  28. type LogConfig struct {
  29. LicLog string `toml:"lic_log"`
  30. }
  31. // LoadConfig 从给定的 TOML 文件路径加载配置
  32. func LoadConfig(filePath string) *Config {
  33. var config Config
  34. // 读取并解析 TOML 文件
  35. if _, err := toml.DecodeFile(filePath, &config); err != nil {
  36. log.Fatalf("无法解析配置文件: %s", err)
  37. }
  38. return &config
  39. }