This commit is contained in:
coward
2024-07-05 14:41:35 +08:00
commit 1f7f57ec9f
70 changed files with 4923 additions and 0 deletions

12
config/config.go Normal file
View File

@@ -0,0 +1,12 @@
package config
var Config *config
type config struct {
Http *http `yaml:"http"`
Database *database `yaml:"database"`
Redis *redis `yaml:"redis"`
File *file `yaml:"file"`
Mail *mail `yaml:"email"`
Wireguard *wireguard `yaml:"wireguard"`
}

25
config/databse.go Normal file
View 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 ""
}

10
config/file.go Normal file
View 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
View File

@@ -0,0 +1,6 @@
package config
type http struct {
Port uint `yaml:"port"`
Endpoint string `yaml:"endpoint"`
}

9
config/mail.go Normal file
View File

@@ -0,0 +1,9 @@
package config
type mail struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
User string `json:"user" yaml:"user"`
Password string `json:"password" yaml:"password"`
SkipTls bool `json:"skipTls" yaml:"skipTls"`
}

8
config/redis.go Normal file
View 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"`
}

6
config/wireguard.go Normal file
View File

@@ -0,0 +1,6 @@
package config
type wireguard struct {
RestartMode string `json:"restartMode"` // 重启模式 NOW - 立即重启 | DELAY - 延时 | HAND - 手动重启
DelayTime int64 `json:"delayTime"` // 延时重启的间隔(单位:秒)
}