:tada:初步完成用户
This commit is contained in:
30
config/database.go
Normal file
30
config/database.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
|
||||
type database struct {
|
||||
Driver string `yaml:"driver"`
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Database string `yaml:"database"`
|
||||
}
|
||||
|
||||
// GetDSN
|
||||
// @description: 获取链接字符串
|
||||
// @receiver d
|
||||
// @return string
|
||||
func (d *database) GetDSN() string {
|
||||
var dsn string
|
||||
switch d.Driver {
|
||||
case "mysql":
|
||||
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", d.User, d.Password, d.Host, d.Port, d.Database)
|
||||
case "pgsql":
|
||||
dsn = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai", d.Host, d.User, d.Password, d.Database, d.Port)
|
||||
case "sqlite":
|
||||
dsn = fmt.Sprintf("%s.db", d.Database)
|
||||
}
|
||||
|
||||
return dsn
|
||||
}
|
||||
Reference in New Issue
Block a user