config.go 856 B

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