-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_source.go
52 lines (49 loc) · 961 Bytes
/
data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sq
import (
"net/url"
"strings"
)
type MysqlDataSource struct {
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
DB string `yaml:"db"`
// DefaultQuery
// map[string]string{
// "charset": "utf8",
// "parseTime": "True",
// "loc": "Local",
// }
Query map[string]string `yaml:"query"`
}
func (config MysqlDataSource) FormatDSN() (dataSourceName string) {
configList := []string{
config.User,
":",
config.Password,
"@",
"(",
config.Host,
":",
config.Port,
")",
"/",
config.DB,
"?",
}
configList = append(configList)
if config.Query == nil {
config.Query = map[string]string{
"charset": "utf8mb4",
"parseTime": "True",
"loc": "Local",
}
}
values := url.Values{}
for key, value := range config.Query {
values.Set(key, value)
}
dataSourceName = strings.Join(configList, "") + values.Encode()
return
}