config.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }
  15. type DatabaseConfig struct {
  16. OADBIP string `toml:"oadb_ip"`
  17. OADBPort string `toml:"oadb_port"`
  18. OADBDb string `toml:"oadb_db"`
  19. OADBUser string `toml:"oadb_user"`
  20. OADBPass string `toml:"oadb_password"`
  21. LicDBIP string `toml:"licdb_ip"`
  22. LicDBPort string `toml:"licdb_port"`
  23. LicDBDb string `toml:"licdb_db"`
  24. LicDBUser string `toml:"licdb_user"`
  25. LicDBPass string `toml:"licdb_password"`
  26. }
  27. type LogConfig struct {
  28. LicLog string `toml:"lic_log"`
  29. }
  30. // LoadConfig 从给定的 TOML 文件路径加载配置
  31. func LoadConfig(filePath string) *Config {
  32. var config Config
  33. // 读取并解析 TOML 文件
  34. if _, err := toml.DecodeFile(filePath, &config); err != nil {
  35. log.Fatalf("无法解析配置文件: %s", err)
  36. }
  37. return &config
  38. }