changed handlers summoning
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
env GOBIN=/usr/local/bin go install ./cmd
|
go build -o /usr/local/bin/mdb ./cmd
|
||||||
@@ -1,31 +1,49 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"log" // Додано імпорт log
|
||||||
|
|
||||||
"github.com/iancoleman/strcase"
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"git.kplus.net.ua/yevhen/resource-scraper/pkg/service"
|
"git.kplus.net.ua/yevhen/resource-scraper/pkg/service"
|
||||||
"git.kplus.net.ua/yevhen/resource-scraper/types/constant"
|
"git.kplus.net.ua/yevhen/resource-scraper/types/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// consoleCommandHandler визначає тип для функцій-обробників консольних команд.
|
||||||
|
type consoleCommandHandler func() string
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
services *service.Service
|
services *service.Service
|
||||||
|
// consoleCommands зберігає мапу назв команд до відповідних функцій-обробників.
|
||||||
|
consoleCommands map[string]consoleCommandHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(services *service.Service) *Handler {
|
func New(services *service.Service) *Handler {
|
||||||
return &Handler{services: services}
|
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 {
|
func (h *Handler) InitConsole() string {
|
||||||
methodName := strcase.ToCamel(viper.GetString(constant.FlagScopeEnable))
|
commandName := viper.GetString(constant.FlagScopeEnable)
|
||||||
|
|
||||||
immutable := reflect.ValueOf(h)
|
if cmdFunc, ok := h.consoleCommands[commandName]; ok {
|
||||||
method := immutable.MethodByName(methodName)
|
return commandName + " launched, " + cmdFunc() + "\n"
|
||||||
v := method.Call(nil)
|
} else {
|
||||||
|
log.Printf("Error: unknown console command '%s'", commandName)
|
||||||
return methodName + " launched, " + v[0].String() + "\n"
|
return "Error: unknown console command"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) InitRoutes() string {
|
func (h *Handler) InitRoutes() string {
|
||||||
|
|||||||
@@ -44,13 +44,11 @@ func (s *ShareTheBrutality) GetMail(email string) ([]model.ExternalSources, *mai
|
|||||||
searchCriteria := &imap.SearchCriteria{
|
searchCriteria := &imap.SearchCriteria{
|
||||||
Text: viper.GetStringSlice(criteria),
|
Text: viper.GetStringSlice(criteria),
|
||||||
}
|
}
|
||||||
//now := carbon.Now()
|
|
||||||
s.EmailService.ListMessages(viper.GetStringSlice(mailboxes), searchCriteria)
|
s.EmailService.ListMessages(viper.GetStringSlice(mailboxes), searchCriteria)
|
||||||
//box.CreateMailbox("INBOX/Processed")
|
|
||||||
//s.EmailService.CreateMailbox("Succeed")
|
//s.EmailService.CreateMailbox("Succeed")
|
||||||
//s.EmailService.DeleteMailbox("Succeed")
|
//s.EmailService.DeleteMailbox("Succeed")
|
||||||
|
//s.EmailService.MailboxesList()
|
||||||
s.EmailService.MailboxesList()
|
|
||||||
|
|
||||||
entries := s.Processing(viper.GetStringMapString(fmt.Sprintf("%s.sender", s.scope)))
|
entries := s.Processing(viper.GetStringMapString(fmt.Sprintf("%s.sender", s.scope)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user