diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/application/menuhandler.go similarity index 99% rename from internal/handlers/ussd/menuhandler.go rename to internal/handlers/application/menuhandler.go index 607b812..52b42b3 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/application/menuhandler.go @@ -1,4 +1,4 @@ -package ussd +package application import ( "bytes" diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/application/menuhandler_test.go similarity index 99% rename from internal/handlers/ussd/menuhandler_test.go rename to internal/handlers/application/menuhandler_test.go index af1380d..bb6230e 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/application/menuhandler_test.go @@ -1,4 +1,4 @@ -package ussd +package application import ( "context" diff --git a/internal/handlers/base.go b/internal/handlers/base.go index 755cca4..6c77f49 100644 --- a/internal/handlers/base.go +++ b/internal/handlers/base.go @@ -6,46 +6,46 @@ import ( "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" - "git.grassecon.net/urdt/ussd/internal/handlers/ussd" + "git.grassecon.net/urdt/ussd/internal/handlers/application" "git.grassecon.net/urdt/ussd/internal/storage" ) type BaseSessionHandler struct { cfgTemplate engine.Config - rp RequestParser - rs resource.Resource - hn *ussd.Handlers - provider storage.StorageProvider + rp RequestParser + rs resource.Resource + hn *application.Handlers + provider storage.StorageProvider } -func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn *ussd.Handlers) *BaseSessionHandler { +func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn *application.Handlers) *BaseSessionHandler { return &BaseSessionHandler{ cfgTemplate: cfg, - rs: rs, - hn: hn, - rp: rp, - provider: storage.NewSimpleStorageProvider(stateDb, userdataDb), + rs: rs, + hn: hn, + rp: rp, + provider: storage.NewSimpleStorageProvider(stateDb, userdataDb), } } -func(f* BaseSessionHandler) Shutdown() { +func (f *BaseSessionHandler) Shutdown() { err := f.provider.Close() if err != nil { logg.Errorf("handler shutdown error", "err", err) } } -func(f *BaseSessionHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine { +func (f *BaseSessionHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine { en := engine.NewEngine(cfg, rs) en = en.WithPersister(pr) return en } -func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) { +func (f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) { var r bool var err error var ok bool - + logg.InfoCtxf(rqs.Ctx, "new request", "data", rqs) rqs.Storage, err = f.provider.Get(rqs.Config.SessionId) @@ -84,25 +84,25 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error) return rqs, err } - rqs.Continue = r + rqs.Continue = r return rqs, nil } -func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession, error) { +func (f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession, error) { var err error _, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) return rqs, err } -func(f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) { +func (f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) { defer f.provider.Put(rqs.Config.SessionId, rqs.Storage) return rqs, rqs.Engine.Finish() } -func(f *BaseSessionHandler) GetConfig() engine.Config { +func (f *BaseSessionHandler) GetConfig() engine.Config { return f.cfgTemplate } -func(f *BaseSessionHandler) GetRequestParser() RequestParser { +func (f *BaseSessionHandler) GetRequestParser() RequestParser { return f.rp } diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 0d49b0c..666ff14 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -10,13 +10,13 @@ import ( "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" - "git.grassecon.net/urdt/ussd/internal/handlers/ussd" + "git.grassecon.net/urdt/ussd/internal/handlers/application" "git.grassecon.net/urdt/ussd/internal/utils" "git.grassecon.net/urdt/ussd/remote" ) type HandlerService interface { - GetHandler() (*ussd.Handlers, error) + GetHandler() (*application.Handlers, error) } func getParser(fp string, debug bool) (*asm.FlagParser, error) { @@ -64,12 +64,12 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) { ls.UserdataStore = db } -func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*ussd.Handlers, error) { +func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*application.Handlers, error) { replaceSeparatorFunc := func(input string) string { return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator) } - ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc) + appHandlers, err := application.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn ls.DbRs.AddLocalFunc("set_back", ussdHandlers.SetBack) ls.DbRs.AddLocalFunc("show_blocked_account", ussdHandlers.ShowBlockedAccount) - return ussdHandlers, nil + return appHandlers, nil } // TODO: enable setting of sessionId on engine init time