🎉初步完成用户
This commit is contained in:
9
config/cache.go
Normal file
9
config/cache.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type cache struct {
|
||||
Driver string `yaml:"driver"`
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Db int `yaml:"db"`
|
||||
}
|
10
config/config.go
Normal file
10
config/config.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package config
|
||||
|
||||
var GlobalConfig *config
|
||||
|
||||
type config struct {
|
||||
Http *http `yaml:"http"`
|
||||
Database *database `yaml:"database"`
|
||||
Cache *cache `yaml:"cache"`
|
||||
File *file `yaml:"file"`
|
||||
}
|
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
|
||||
}
|
10
config/file.go
Normal file
10
config/file.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package config
|
||||
|
||||
type file struct {
|
||||
Type string `yaml:"type"`
|
||||
Path string `yaml:"path"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
AccessId string `yaml:"accessId"`
|
||||
AccessSecret string `yaml:"accessSecret"`
|
||||
BucketName string `yaml:"bucketName"`
|
||||
}
|
6
config/http.go
Normal file
6
config/http.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type http struct {
|
||||
Port int `yaml:"port"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
}
|
Reference in New Issue
Block a user