Fix symptom of handler missing persister

This commit is contained in:
lash 2024-09-11 17:53:12 +01:00
parent 836e5fe8ee
commit 514e043e38
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 12 additions and 12 deletions

View File

@ -16,7 +16,6 @@ import (
fsdb "git.defalsify.org/vise.git/db/fs" fsdb "git.defalsify.org/vise.git/db/fs"
gdbmdb "git.defalsify.org/vise.git/db/gdbm" gdbmdb "git.defalsify.org/vise.git/db/gdbm"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
@ -113,12 +112,6 @@ func getResource(resourceDir string, ctx context.Context) (resource.Resource, er
return rfs, nil return rfs, nil
} }
func getEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) *engine.DefaultEngine {
en := engine.NewEngine(cfg, rs)
en = en.WithPersister(pr)
return en
}
func main() { func main() {
var dbDir string var dbDir string
var resourceDir string var resourceDir string
@ -196,7 +189,8 @@ func main() {
defer stateStore.Close() defer stateStore.Close()
rp := &httpserver.DefaultRequestParser{} rp := &httpserver.DefaultRequestParser{}
sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl.Init) //sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl.Init)
sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
s := &http.Server{ s := &http.Server{
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))), Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: sh, Handler: sh,

View File

@ -10,6 +10,8 @@ import (
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
) )
var ( var (
@ -45,15 +47,18 @@ type SessionHandler struct {
cfgTemplate engine.Config cfgTemplate engine.Config
rp RequestParser rp RequestParser
rs resource.Resource rs resource.Resource
first resource.EntryFunc //first resource.EntryFunc
hn *ussd.Handlers
provider StorageProvider provider StorageProvider
} }
func NewSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, first resource.EntryFunc) *SessionHandler { //func NewSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, first resource.EntryFunc) *SessionHandler {
func NewSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp RequestParser, hn *ussd.Handlers) *SessionHandler {
return &SessionHandler{ return &SessionHandler{
cfgTemplate: cfg, cfgTemplate: cfg,
rs: rs, rs: rs,
first: first, //first: first,
hn: hn,
rp: rp, rp: rp,
provider: NewSimpleStorageProvider(stateDb, userdataDb), provider: NewSimpleStorageProvider(stateDb, userdataDb),
} }
@ -101,9 +106,10 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
f.writeError(w, 500, "Storage retrieval fail", err) f.writeError(w, 500, "Storage retrieval fail", err)
return return
} }
f.hn = f.hn.WithPersister(storage.Persister)
defer f.provider.Put(cfg.SessionId, storage) defer f.provider.Put(cfg.SessionId, storage)
en := getEngine(cfg, f.rs, storage.Persister) en := getEngine(cfg, f.rs, storage.Persister)
en = en.WithFirst(f.first) en = en.WithFirst(f.hn.Init)
if cfg.EngineDebug { if cfg.EngineDebug {
en = en.WithDebug(nil) en = en.WithDebug(nil)
} }