Files
resource-scraper/pkg/handler/handler.go

53 lines
1.4 KiB
Go

package handler
import (
"log" // Додано імпорт log
"github.com/spf13/viper"
"git.kplus.net.ua/yevhen/resource-scraper/pkg/service"
"git.kplus.net.ua/yevhen/resource-scraper/types/constant"
)
// consoleCommandHandler визначає тип для функцій-обробників консольних команд.
type consoleCommandHandler func() string
type Handler struct {
services *service.Service
// consoleCommands зберігає мапу назв команд до відповідних функцій-обробників.
consoleCommands map[string]consoleCommandHandler
}
func New(services *service.Service) *Handler {
h := &Handler{services: services}
// Ініціалізація мапи команд.
h.consoleCommands = map[string]consoleCommandHandler{
"console": h.Console,
"info": h.Info,
"metal-archives": h.MetalArchives,
"prescene": h.Prescene,
"rutracker": h.Rutracker,
"stb": h.STB,
//"web": h.Web,
}
return h
}
func (h *Handler) InitConsole() string {
commandName := viper.GetString(constant.FlagScopeEnable)
if cmdFunc, ok := h.consoleCommands[commandName]; ok {
return commandName + " launched, " + cmdFunc() + "\n"
} else {
log.Printf("Error: unknown console command '%s'", commandName)
return "Error: unknown console command"
}
}
func (h *Handler) InitRoutes() string {
//TODO:
return "i am the web initiator"
}