Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test.go 893B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "git.x2erp.com/qdy/go-base/config"
  6. "git.x2erp.com/qdy/go-db/factory"
  7. )
  8. func main() {
  9. // 显示当前使用的数据库配置
  10. config := config.GetConfig()
  11. dbConfig := config.GetDatabase() // 通过接口方法获取数据库配置
  12. fmt.Printf("Using database type: %s\n", dbConfig.Type)
  13. fmt.Printf("Database host: %s:%d\n", dbConfig.Host, dbConfig.Port)
  14. fmt.Printf("Database name: %s\n", dbConfig.Database)
  15. // 创建数据库工厂
  16. fmt.Printf("第1次.\n")
  17. dbFactory, err := factory.GetDBFactory()
  18. if err != nil {
  19. log.Fatalf("Failed to create DB factory: %v", err)
  20. }
  21. //测试单例是否生效
  22. fmt.Printf("第2次.\n")
  23. dbFactory1, err1 := factory.GetDBFactory()
  24. if err1 != nil {
  25. log.Fatalf("Failed to create DB factory: %v", err1)
  26. }
  27. dbFactory1.TestConnection(dbConfig.Type)
  28. defer dbFactory.Close()
  29. defer dbFactory1.Close()
  30. }