| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package main
-
- import (
- "fmt"
- "log"
-
- "git.x2erp.com/qdy/go-base/config"
- "git.x2erp.com/qdy/go-db/factory"
- )
-
- func main() {
-
- // 显示当前使用的数据库配置
- config := config.GetConfig()
- dbConfig := config.GetDatabase() // 通过接口方法获取数据库配置
- fmt.Printf("Using database type: %s\n", dbConfig.Type)
- fmt.Printf("Database host: %s:%d\n", dbConfig.Host, dbConfig.Port)
- fmt.Printf("Database name: %s\n", dbConfig.Database)
-
- // 创建数据库工厂
- fmt.Printf("第1次.\n")
- dbFactory, err := factory.GetDBFactory()
-
- if err != nil {
- log.Fatalf("Failed to create DB factory: %v", err)
- }
-
- //测试单例是否生效
- fmt.Printf("第2次.\n")
- dbFactory1, err1 := factory.GetDBFactory()
-
- if err1 != nil {
- log.Fatalf("Failed to create DB factory: %v", err1)
- }
- dbFactory1.TestConnection(dbConfig.Type)
- defer dbFactory.Close()
- defer dbFactory1.Close()
-
- }
|