91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
/*
|
|
* Copyright (c) 2025-2026, Антон Аксенов
|
|
* This file is part of iptvc project
|
|
* MIT License: https://git.axenov.dev/IPTV/iptvc/src/branch/master/LICENSE
|
|
*/
|
|
|
|
package app
|
|
|
|
import (
|
|
"axenov/iptv-checker/app/cache"
|
|
"axenov/iptv-checker/app/config"
|
|
"axenov/iptv-checker/app/logger"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
// Version информация, заполняется при сборке через ldflags
|
|
var (
|
|
VERSION = "dev"
|
|
COMMIT = "unknown"
|
|
)
|
|
|
|
// Arguments описывает аргументы командной строки
|
|
type Arguments struct {
|
|
IniPath string
|
|
TagsPath string
|
|
RandomCount uint
|
|
RepeatCount uint
|
|
NeedJson bool
|
|
NeedQuiet bool
|
|
Verbose bool
|
|
ServerPort uint
|
|
ServerHost string
|
|
ConfigPath string
|
|
NeedCheck bool
|
|
Files []string
|
|
Urls []string
|
|
Codes []string
|
|
|
|
// app
|
|
Debug bool
|
|
LogLevel string
|
|
|
|
// check.playlists
|
|
PlTimeout int
|
|
PlAllCooldown int
|
|
PlOneCooldown int
|
|
PlMaxRoutines int
|
|
PlPerRoutine int
|
|
PlUserAgent []string
|
|
|
|
// check.channels
|
|
ChTimeout int
|
|
ChByteRange int
|
|
ChCooldown int
|
|
ChMaxRoutines int
|
|
ChPerRoutine int
|
|
ChUserAgent []string
|
|
|
|
// cache
|
|
CacheEnabled bool
|
|
CacheHost string
|
|
CachePort uint
|
|
CacheUsername string
|
|
CachePassword string
|
|
CacheDb uint
|
|
CacheTtl uint
|
|
}
|
|
|
|
var (
|
|
Args Arguments
|
|
Cache *redis.Client
|
|
Config *config.Config
|
|
)
|
|
|
|
// Init загружает конфигурацию и инициализирует логгер.
|
|
// CLI-override применяются через applyAppOverrides(), applyCacheOverrides()
|
|
// и applyCheckOverrides() в обработчиках команд после Init().
|
|
func Init() {
|
|
Config = config.Init(Args.ConfigPath)
|
|
logger.Init(Args.NeedQuiet)
|
|
}
|
|
|
|
// InitCache инициализирует подключение к KeyDB/Redis, если кеш включён.
|
|
// Вызывайте после применения всех cache-override.
|
|
func InitCache() {
|
|
if Config.Cache.Enabled {
|
|
Cache = cache.Init(&Config.Cache)
|
|
}
|
|
}
|