geoGo/internal/config/config.go

73 lines
2.1 KiB
Go

package config
import (
"os"
"path/filepath"
)
// Config 应用配置
type Config struct {
Server ServerConfig `mapstructure:"server"`
DB DB `mapstructure:"db"`
Sys Sys `mapstructure:"sys"`
}
// ServerConfig 服务器配置
type ServerConfig struct {
Port int `mapstructure:"port"`
Host string `mapstructure:"host"`
}
type DB struct {
Driver string `mapstructure:"driver"`
Source string `mapstructure:"source"`
MaxIdle int32 `mapstructure:"maxIdle"`
MaxOpen int32 `mapstructure:"maxOpen"`
MaxLifetime int32 `mapstructure:"maxLifetime"`
IsDebug bool `mapstructure:"isDebug"`
}
type Sys struct {
MaxConcurrent int `mapstructure:"maxConcurrent"`
TaskTimeout int `mapstructure:"taskTimeout"`
SessionTimeout int `mapstructure:"sessionTimeout "`
MaxImageSize int `mapstructure:"maxImageSize"`
LogsDir string `mapstructure:"logsDir"`
UploadDir string `mapstructure:"uploadDir"`
VideosDir string `mapstructure:"videosDir"`
DocsDir string `mapstructure:"docsDir"`
CookiesDir string `mapstructure:"cookiesDir"`
QrcodesDir string `mapstructure:"qrcodesDir"`
ChromePath string `mapstructure:"chromePath"`
ChromeDataDir string `mapstructure:"chromeDataDir"`
}
// LoadConfig 加载配置
func LoadConfig() (*Config, error) {
BaseDir, _ := os.Getwd()
return &Config{
Server: ServerConfig{
Port: 5001,
Host: "0.0.0.0",
},
DB: DB{
Driver: "mysql",
Source: "root:lansexiongdi6,@tcp(47.97.27.195:3306)/geo?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai",
},
Sys: Sys{
MaxConcurrent: 1,
TaskTimeout: 60,
SessionTimeout: 300,
MaxImageSize: 5 * 1024 * 1024,
LogsDir: filepath.Join(BaseDir, "logs"),
UploadDir: filepath.Join(BaseDir, "images"),
VideosDir: filepath.Join(BaseDir, "videos"),
DocsDir: filepath.Join(BaseDir, "docs"),
CookiesDir: filepath.Join(BaseDir, "cookies"),
QrcodesDir: filepath.Join(BaseDir, "qrcodes"),
ChromePath: "./chrome/chrome.exe",
ChromeDataDir: "./chrome_data",
},
}, nil
}