geoGo/internal/config/config.go

103 lines
3.3 KiB
Go

package config
import (
"os"
"path/filepath"
)
// Config 应用配置
type Config struct {
Server ServerConfig `mapstructure:"server"`
DB DB `mapstructure:"db"`
Sys Sys `mapstructure:"sys"`
Hsyq Hsyq `mapstructure:"hsyq"`
Oss Oss `mapstructure:"oss"`
}
type Oss struct {
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
Bucket string `mapstructure:"bucket"`
Domain string `mapstructure:"domain"`
Endpoint string `mapstructure:"endpoint"`
FilePath string `mapstructure:"filepath"`
}
// ServerConfig 服务器配置
type ServerConfig struct {
Port int `mapstructure:"port"`
Host string `mapstructure:"host"`
}
type Hsyq struct {
ApiKey string `mapstructure:"api_key"`
}
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 {
AutoPublishWorkers int `yaml:"auto_publish_workers"`
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"`
MdDir string `mapstructure:"mdDIr"`
}
// LoadConfig 加载配置
func LoadConfig() (*Config, error) {
BaseDir, _ := os.Getwd()
return &Config{
Server: ServerConfig{
Port: 5001,
Host: "0.0.0.0",
}, //root:lansexiongdi6,@tcp(47.97.27.195:3306)/geo?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
DB: DB{
Driver: "mysql",
Source: "root:Renzhiyuan123.@tcp(8.137.19.81:3306)/geo?charset=utf8mb4&parseTime=true&loc=Local",
},
Sys: Sys{
AutoPublishWorkers: 5,
MaxConcurrent: 1,
TaskTimeout: 200,
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: filepath.Join(BaseDir, "chrome", "chrome.exe"),
ChromeDataDir: filepath.Join(BaseDir, "chrome_data"),
MdDir: filepath.Join(BaseDir, "md"),
},
Hsyq: Hsyq{
ApiKey: "236ba4b6-9daa-4755-b22f-2fd274cd223a",
},
Oss: Oss{
AccessKey: "LTAI5tGGZzjf3tvqWk8SQj2G",
SecretKey: "S0NKOAUaYWoK4EGSxrMFmYDzllhvpq",
Bucket: "attachment-public",
Domain: "https://attachment-public.oss-cn-hangzhou.aliyuncs.com",
Endpoint: "https://oss-cn-hangzhou.aliyuncs.com",
FilePath: "geo/",
},
}, nil
}