refactor: rename ussd package to application (#24)
- Rename internal/handlers/ussd directory to application - Update all imports and references to use new package name
This commit is contained in:
parent
f40e11c267
commit
bf4a60cd4e
@ -1,4 +1,4 @@
|
||||
package ussd
|
||||
package application
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,4 +1,4 @@
|
||||
package ussd
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
@ -6,42 +6,42 @@ 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
|
||||
@ -88,21 +88,21 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
||||
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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user