Skip to content

Commit 3f2e86b

Browse files
committed
第三方组件配置 添加yaml兼容
1 parent 8b65514 commit 3f2e86b

File tree

8 files changed

+56
-47
lines changed

8 files changed

+56
-47
lines changed

db/db_type_sqlite/db_sqlite3.go

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ func init() {
1414
dsn := config.Dsn
1515
if dsn == "" {
1616
dsn = "file:" + config.DatabasePath + "?cache=shared"
17+
if config.Username != "" {
18+
dsn += "&_auth_user=" + config.Username
19+
}
20+
if config.Password != "" {
21+
dsn += "&_auth_pass=" + config.Password
22+
}
23+
if config.Username != "" && config.Password != "" {
24+
dsn += "&_auth=true"
25+
}
1726
}
1827
db, err = db_sqlite3.Open(dsn)
1928
return

db/service.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ import (
1717
)
1818

1919
type Config struct {
20-
Type string `json:"type,omitempty"`
21-
Host string `json:"host,omitempty"`
22-
Port int `json:"port,omitempty"`
23-
Database string `json:"database,omitempty"`
24-
DbName string `json:"dbName,omitempty"`
25-
Username string `json:"username,omitempty"`
26-
Password string `json:"password,omitempty"`
27-
OdbcDsn string `json:"odbcDsn,omitempty"`
28-
OdbcDialectName string `json:"odbcDialectName,omitempty"`
29-
30-
Schema string `json:"schema,omitempty"`
31-
Sid string `json:"sid,omitempty"`
32-
MaxIdleConn int `json:"maxIdleConn,omitempty"`
33-
MaxOpenConn int `json:"maxOpenConn,omitempty"`
34-
DatabasePath string `json:"databasePath,omitempty"`
20+
Type string `json:"type,omitempty" yaml:"type,omitempty"`
21+
Host string `json:"host,omitempty" yaml:"host,omitempty"`
22+
Port int `json:"port,omitempty" yaml:"port,omitempty"`
23+
Database string `json:"database,omitempty" yaml:"database,omitempty"`
24+
DbName string `json:"dbName,omitempty" yaml:"dbName,omitempty"`
25+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
26+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
27+
OdbcDsn string `json:"odbcDsn,omitempty" yaml:"odbcDsn,omitempty"`
28+
OdbcDialectName string `json:"odbcDialectName,omitempty" yaml:"odbcDialectName,omitempty"`
29+
30+
Schema string `json:"schema,omitempty" yaml:"schema,omitempty"`
31+
Sid string `json:"sid,omitempty" yaml:"sid,omitempty"`
32+
MaxIdleConn int `json:"maxIdleConn,omitempty" yaml:"maxIdleConn,omitempty"`
33+
MaxOpenConn int `json:"maxOpenConn,omitempty" yaml:"maxOpenConn,omitempty"`
34+
DatabasePath string `json:"databasePath,omitempty" yaml:"databasePath,omitempty"`
3535
SSHClient *ssh.Client `json:"-"`
36-
Dsn string `json:"dsn,omitempty"`
36+
Dsn string `json:"dsn,omitempty" yaml:"dsn,omitempty"`
3737

38-
TlsConfig string `json:"tlsConfig,omitempty"`
39-
TlsRootCert string `json:"tlsRootCert,omitempty"`
40-
TlsClientCert string `json:"tlsClientCert,omitempty"`
41-
TlsClientKey string `json:"tlsClientKey,omitempty"`
38+
TlsConfig string `json:"tlsConfig,omitempty" yaml:"tlsConfig,omitempty"`
39+
TlsRootCert string `json:"tlsRootCert,omitempty" yaml:"tlsRootCert,omitempty"`
40+
TlsClientCert string `json:"tlsClientCert,omitempty" yaml:"tlsClientCert,omitempty"`
41+
TlsClientKey string `json:"tlsClientKey,omitempty" yaml:"tlsClientKey,omitempty"`
4242
}
4343

4444
// New 创建 db客户端

elasticsearch/service.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package elasticsearch
22

33
type Config struct {
4-
Url string `json:"url,omitempty"`
5-
Username string `json:"username,omitempty"`
6-
Password string `json:"password,omitempty"`
7-
CertPath string `json:"certPath,omitempty"`
4+
Url string `json:"url,omitempty" yaml:"url,omitempty"`
5+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
6+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
7+
CertPath string `json:"certPath,omitempty" yaml:"certPath,omitempty"`
88
}
99

1010
func New(config *Config) (IService, error) {

kafka/service.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package kafka
22

33
// Config kafka配置
44
type Config struct {
5-
Address string `json:"address"`
6-
Username string `json:"username,omitempty"`
7-
Password string `json:"password,omitempty"`
8-
CertPath string `json:"certPath,omitempty"`
5+
Address string `json:"address" yaml:"address"`
6+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
7+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
8+
CertPath string `json:"certPath,omitempty" yaml:"certPath,omitempty"`
99
}
1010

1111
// New 创建kafka服务

mongodb/service.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package mongodb
22

33
type Config struct {
4-
Address string `json:"address"`
5-
Username string `json:"username,omitempty"`
6-
Password string `json:"password,omitempty"`
7-
MinPoolSize int `json:"minPoolSize,omitempty"`
8-
MaxPoolSize int `json:"maxPoolSize,omitempty"`
9-
ConnectTimeout int `json:"connectTimeout,omitempty"` // 客户端连接超时 单位 毫秒
10-
CertPath string `json:"certPath,omitempty"`
4+
Address string `json:"address" yaml:"address"`
5+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
6+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
7+
MinPoolSize int `json:"minPoolSize,omitempty" yaml:"minPoolSize,omitempty"`
8+
MaxPoolSize int `json:"maxPoolSize,omitempty" yaml:"maxPoolSize,omitempty"`
9+
ConnectTimeout int `json:"connectTimeout,omitempty" yaml:"connectTimeout,omitempty"` // 客户端连接超时 单位 毫秒
10+
CertPath string `json:"certPath,omitempty" yaml:"certPath,omitempty"`
1111
}
1212

1313
// New 创建 mongodb 客户端

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "1.2.30"
2+
"version": "1.2.31"
33
}

redis/service.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
)
77

88
type Config struct {
9-
Address string `json:"address"`
10-
Auth string `json:"auth"`
11-
Username string `json:"username"`
12-
CertPath string `json:"certPath"`
13-
Servers []string `json:"servers"`
9+
Address string `json:"address" yaml:"address"`
10+
Auth string `json:"auth" yaml:"auth"`
11+
Username string `json:"username" yaml:"username"`
12+
CertPath string `json:"certPath" yaml:"certPath"`
13+
Servers []string `json:"servers" yaml:"servers"`
1414
SSHClient *ssh.Client `json:"-"`
15-
ThrowNotFoundErr bool `json:"throwNotFoundErr"` // 是否 抛出 值 不存在异常
15+
ThrowNotFoundErr bool `json:"throwNotFoundErr" yaml:"throwNotFoundErr"` // 是否 抛出 值 不存在异常
1616
}
1717

1818
// New 创建Redis服务

zookeeper/service.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
)
66

77
type Config struct {
8-
Address string `json:"address"`
9-
Username string `json:"username,omitempty"`
10-
Password string `json:"password,omitempty"`
11-
SessionTimeout int `json:"sessionTimeout,omitempty"` // 会话超时 单位 毫秒
12-
ConnectionTimeout int `json:"connectionTimeout,omitempty"` // 客户端连接超时 单位 毫秒
8+
Address string `json:"address" yaml:"address"`
9+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
10+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
11+
SessionTimeout int `json:"sessionTimeout,omitempty" yaml:"sessionTimeout,omitempty"` // 会话超时 单位 毫秒
12+
ConnectionTimeout int `json:"connectionTimeout,omitempty" yaml:"connectionTimeout,omitempty"` // 客户端连接超时 单位 毫秒
1313
SSHClient *ssh.Client `json:"-"`
1414
}
1515

0 commit comments

Comments
 (0)