🎉
This commit is contained in:
9
config/config.go
Normal file
9
config/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
var Config *config
|
||||
|
||||
type config struct {
|
||||
Http *http `yaml:"http"`
|
||||
Database *database `yaml:"database"`
|
||||
Redis *redis `yaml:"redis"`
|
||||
}
|
25
config/databse.go
Normal file
25
config/databse.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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"`
|
||||
Db string `yaml:"db"`
|
||||
}
|
||||
|
||||
func (d database) GetDSN() string {
|
||||
switch d.Driver {
|
||||
case "mysql":
|
||||
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", d.User, d.Password, d.Host, d.Port, d.Db)
|
||||
case "pgsql":
|
||||
return fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai", d.Host, d.User, d.Password, d.Db, d.Port)
|
||||
case "sqlite":
|
||||
return fmt.Sprintf("%s.db", d.Db)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
5
config/http.go
Normal file
5
config/http.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
type http struct {
|
||||
Port uint `yaml:"port"`
|
||||
}
|
8
config/redis.go
Normal file
8
config/redis.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
type redis struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Db int `yaml:"db"`
|
||||
}
|
Reference in New Issue
Block a user