8
8
"sync"
9
9
)
10
10
11
- // MySQLConnectionManager 创建一个MySQL的连接管理器
12
- type MySQLConnectionManager struct {
11
+ // MysqlConnectionManager 创建一个MySQL的连接管理器
12
+ type MysqlConnectionManager struct {
13
13
14
14
// 主机的名字
15
15
Host string
@@ -33,18 +33,18 @@ type MySQLConnectionManager struct {
33
33
once sync.Once
34
34
}
35
35
36
- var _ storage.ConnectionManager [* sql.DB ] = & MySQLConnectionManager {}
36
+ var _ storage.ConnectionManager [* sql.DB ] = & MysqlConnectionManager {}
37
37
38
- // NewMySQLConnectionManagerFromDSN 从DSN创建MySQL连接管理器
39
- func NewMySQLConnectionManagerFromDSN (dsn string ) * MySQLConnectionManager {
40
- return & MySQLConnectionManager {
38
+ // NewMysqlConnectionManagerFromDSN 从DSN创建MySQL连接管理器
39
+ func NewMysqlConnectionManagerFromDSN (dsn string ) * MysqlConnectionManager {
40
+ return & MysqlConnectionManager {
41
41
DSN : dsn ,
42
42
}
43
43
}
44
44
45
- // NewMySQLConnectionManager 从连接属性创建数据库连接
46
- func NewMySQLConnectionManager (host string , port uint , user , passwd , database string ) * MySQLConnectionManager {
47
- return & MySQLConnectionManager {
45
+ // NewMysqlConnectionManager 从连接属性创建数据库连接
46
+ func NewMysqlConnectionManager (host string , port uint , user , passwd , database string ) * MysqlConnectionManager {
47
+ return & MysqlConnectionManager {
48
48
Host : host ,
49
49
Port : port ,
50
50
User : user ,
@@ -53,39 +53,39 @@ func NewMySQLConnectionManager(host string, port uint, user, passwd, database st
53
53
}
54
54
}
55
55
56
- func (x * MySQLConnectionManager ) SetHost (host string ) * MySQLConnectionManager {
56
+ func (x * MysqlConnectionManager ) SetHost (host string ) * MysqlConnectionManager {
57
57
x .Host = host
58
58
return x
59
59
}
60
60
61
- func (x * MySQLConnectionManager ) SetPort (port uint ) * MySQLConnectionManager {
61
+ func (x * MysqlConnectionManager ) SetPort (port uint ) * MysqlConnectionManager {
62
62
x .Port = port
63
63
return x
64
64
}
65
65
66
- func (x * MySQLConnectionManager ) SetUser (user string ) * MySQLConnectionManager {
66
+ func (x * MysqlConnectionManager ) SetUser (user string ) * MysqlConnectionManager {
67
67
x .User = user
68
68
return x
69
69
}
70
70
71
- func (x * MySQLConnectionManager ) SetPasswd (passwd string ) * MySQLConnectionManager {
71
+ func (x * MysqlConnectionManager ) SetPasswd (passwd string ) * MysqlConnectionManager {
72
72
x .Passwd = passwd
73
73
return x
74
74
}
75
75
76
- func (x * MySQLConnectionManager ) SetDatabaseName (databaseName string ) * MySQLConnectionManager {
76
+ func (x * MysqlConnectionManager ) SetDatabaseName (databaseName string ) * MysqlConnectionManager {
77
77
x .DatabaseName = databaseName
78
78
return x
79
79
}
80
80
81
- const MySQLConnectionManagerName = "mysql-connection-manager"
81
+ const MysqlConnectionManagerName = "mysql-connection-manager"
82
82
83
- func (x * MySQLConnectionManager ) Name () string {
84
- return MySQLConnectionManagerName
83
+ func (x * MysqlConnectionManager ) Name () string {
84
+ return MysqlConnectionManagerName
85
85
}
86
86
87
87
// Take 获取到数据库的连接
88
- func (x * MySQLConnectionManager ) Take (ctx context.Context ) (* sql.DB , error ) {
88
+ func (x * MysqlConnectionManager ) Take (ctx context.Context ) (* sql.DB , error ) {
89
89
x .once .Do (func () {
90
90
db , err := sql .Open ("mysql" , x .GetDSN ())
91
91
if err != nil {
@@ -97,18 +97,18 @@ func (x *MySQLConnectionManager) Take(ctx context.Context) (*sql.DB, error) {
97
97
return x .db , x .err
98
98
}
99
99
100
- func (x * MySQLConnectionManager ) GetDSN () string {
100
+ func (x * MysqlConnectionManager ) GetDSN () string {
101
101
if x .DSN != "" {
102
102
return x .DSN
103
103
}
104
104
return fmt .Sprintf ("%s:%s@tcp(%s:%d)/%s" , x .User , x .Passwd , x .Host , x .Port , x .DatabaseName )
105
105
}
106
106
107
- func (x * MySQLConnectionManager ) Return (ctx context.Context , db * sql.DB ) error {
107
+ func (x * MysqlConnectionManager ) Return (ctx context.Context , db * sql.DB ) error {
108
108
return nil
109
109
}
110
110
111
- func (x * MySQLConnectionManager ) Shutdown (ctx context.Context ) error {
111
+ func (x * MysqlConnectionManager ) Shutdown (ctx context.Context ) error {
112
112
if x .db != nil {
113
113
return x .db .Close ()
114
114
}
0 commit comments