teldrive/utils/config.go

55 lines
2.2 KiB
Go
Raw Normal View History

2023-08-12 19:21:42 +08:00
package utils
import (
2023-08-26 01:32:05 +08:00
"path/filepath"
"github.com/joho/godotenv"
2023-08-12 19:21:42 +08:00
"github.com/kelseyhightower/envconfig"
)
type MultiToken string
type Config struct {
2023-09-08 22:51:54 +08:00
AppId int `envconfig:"APP_ID" required:"true"`
AppHash string `envconfig:"APP_HASH" required:"true"`
JwtSecret string `envconfig:"JWT_SECRET" required:"true"`
Https bool `envconfig:"HTTPS" default:"false"`
CookieSameSite bool `envconfig:"COOKIE_SAME_SITE" default:"true"`
AllowedUsers []string `envconfig:"ALLOWED_USERS"`
DatabaseUrl string `envconfig:"DATABASE_URL" required:"true"`
RateLimit bool `envconfig:"RATE_LIMIT" default:"true"`
2023-09-15 05:10:32 +08:00
RateBurst int `envconfig:"RATE_BURST" default:"5"`
Rate int `envconfig:"RATE" default:"100"`
2023-09-20 03:20:44 +08:00
TgClientDeviceModel string `envconfig:"TG_CLIENT_DEVICE_MODEL" default:"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0"`
2023-09-08 22:51:54 +08:00
TgClientSystemVersion string `envconfig:"TG_CLIENT_SYSTEM_VERSION" default:"Win32"`
TgClientAppVersion string `envconfig:"TG_CLIENT_APP_VERSION" default:"2.1.9 K"`
TgClientLangCode string `envconfig:"TG_CLIENT_LANG_CODE" default:"en"`
TgClientSystemLangCode string `envconfig:"TG_CLIENT_SYSTEM_LANG_CODE" default:"en"`
TgClientLangPack string `envconfig:"TG_CLIENT_LANG_PACK" default:"webk"`
RunMigrations bool `envconfig:"RUN_MIGRATIONS" default:"true"`
Port int `envconfig:"PORT" default:"8080"`
2023-11-08 03:52:26 +08:00
LazyStreamBots bool `envconfig:"LAZY_STREAM_BOTS" default:"false"`
BgBotsLimit int `envconfig:"BG_BOTS_LIMIT" default:"5"`
UploadRetention int `envconfig:"UPLOAD_RETENTION" default:"15"`
2023-11-16 23:21:35 +08:00
DisableStreamBots bool `envconfig:"DISABLE_STREAM_BOTS" default:"false"`
2023-08-26 01:32:05 +08:00
ExecDir string
2023-08-12 19:21:42 +08:00
}
var config Config
func InitConfig() {
2023-08-26 01:32:05 +08:00
execDir := getExecutableDir()
godotenv.Load(filepath.Join(execDir, "teldrive.env"))
2023-08-12 19:21:42 +08:00
err := envconfig.Process("", &config)
if err != nil {
panic(err)
}
2023-08-26 01:32:05 +08:00
config.ExecDir = execDir
2023-08-12 19:21:42 +08:00
}
func GetConfig() *Config {
return &config
}