## 配置類型
### golang原生配置
- 單一數據庫配置
```go
// 單一數據庫配置
type DbConfigSingle struct {
Driver string // 驅動: mysql/sqlite/oracle/mssql/postgres
EnableQueryLog bool // 是否開啟sql日志
SetMaxOpenConns int // (連接池)最大打開的連接數,默認值為0表示不限制
SetMaxIdleConns int // (連接池)閑置的連接數
Prefix string // 表前綴
Dsn string // 數據庫鏈接
}
```
- 數據庫集群配置
```go
// 數據庫集群配置
// 如果不啟用集群, 則直接使用 DbConfig 即可
// 如果仍然使用此配置為非集群, 則 Slave 配置置空即可, 等同于使用 DbConfig
type DbConfigCluster struct {
Slave []*DbConfigSingle // 多臺讀服務器, 如果啟用則需要放入對應的多臺從服務器配置
Master *DbConfigSingle // 一臺主服務器負責寫數據
}
```
### 配置文件示例 - json
- 單一數據庫配置 - json
```json
{
"Driver": "mysql",
"EnableQueryLog": false,
"SetMaxOpenConns": 0,
"SetMaxIdleConns": 0,
"Prefix": "",
"Dsn": "root:root@tcp(localhost:3306)/test?charset=utf8"
}
```
- 數據庫集群配置 - json
```json
{
"Slave": [
{
"Driver": "mysql",
"EnableQueryLog": false,
"SetMaxOpenConns": 0,
"SetMaxIdleConns": 0,
"Prefix": "",
"Dsn": "root:root@tcp(localhost:3306)/test1?charset=utf8"
},
{
"Driver": "mysql",
"EnableQueryLog": false,
"SetMaxOpenConns": 0,
"SetMaxIdleConns": 0,
"Prefix": "",
"Dsn": "root:root@tcp(localhost:3306)/test2?charset=utf8"
}
],
"Master": {
"Driver": "mysql",
"EnableQueryLog": false,
"SetMaxOpenConns": 0,
"SetMaxIdleConns": 0,
"Prefix": "",
"Dsn": "root:root@tcp(localhost:3306)/test?charset=utf8"
}
}
```
理論上可以接收任何文件類型的配置, 只需要添加對應文件類型的解析器即可.
幸運的是, 我們可以輕松擴展文件解析器, 具體擴展方法, 我們可以查看第9節, 擴展開發