alist/internal/conf/config.go

69 lines
2.1 KiB
Go
Raw Normal View History

2022-06-06 13:48:53 +00:00
package conf
2022-06-25 13:34:44 +00:00
import (
"github.com/alist-org/alist/v3/pkg/utils/random"
)
2022-06-06 13:48:53 +00:00
type Database struct {
Type string `json:"type" env:"DB_TYPE"`
Host string `json:"host" env:"DB_HOST"`
Port int `json:"port" env:"DB_PORT"`
User string `json:"user" env:"DB_USER"`
Password string `json:"password" env:"DB_PASS"`
Name string `json:"name" env:"DB_NAME"`
DBFile string `json:"db_file" env:"DB_FILE"`
TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
SSLMode string `json:"ssl_mode" env:"DB_SSL_MODE"`
2022-06-06 13:48:53 +00:00
}
type Scheme struct {
Https bool `json:"https" env:"HTTPS"`
CertFile string `json:"cert_file" env:"CERT_FILE"`
KeyFile string `json:"key_file" env:"KEY_FILE"`
}
type LogConfig struct {
2022-06-09 07:12:34 +00:00
Enable bool `json:"enable" env:"log_enable"`
2022-06-06 13:48:53 +00:00
Path string `json:"path" env:"LOG_PATH"`
Name string `json:"name" env:"LOG_NAME"`
RotationTime uint `json:"rotation_time" env:"LOG_TIME"`
RotationCount uint `json:"rotation_count" env:"LOG_COUNT"`
}
type Config struct {
2022-06-15 12:31:23 +00:00
Force bool `json:"force"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
2022-06-25 13:34:44 +00:00
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
2022-06-15 12:31:23 +00:00
CaCheExpiration int `json:"cache_expiration" env:"CACHE_EXPIRATION"`
Assets string `json:"assets" env:"ASSETS"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
Log LogConfig `json:"log"`
2022-06-06 13:48:53 +00:00
}
func DefaultConfig() *Config {
return &Config{
2022-06-25 13:34:44 +00:00
Address: "0.0.0.0",
Port: 5244,
2022-06-26 11:09:28 +00:00
JwtSecret: random.String(16),
2022-06-25 13:34:44 +00:00
Assets: "https://npm.elemecdn.com/alist-web@$version/dist",
TempDir: "data/temp",
2022-06-06 13:48:53 +00:00
Database: Database{
Type: "sqlite3",
Port: 0,
TablePrefix: "x_",
DBFile: "data/data.db",
},
2022-06-15 12:31:23 +00:00
CaCheExpiration: 30,
2022-06-06 13:48:53 +00:00
Log: LogConfig{
2022-06-09 07:12:34 +00:00
Enable: true,
2022-06-06 13:48:53 +00:00
Path: "log/%Y-%m-%d-%H:%M.log",
Name: "log/log.log",
RotationTime: 24,
RotationCount: 5,
},
}
}