From 514e043e3821be502eb993bc0c9312849234565c Mon Sep 17 00:00:00 2001 From: lash Date: Wed, 11 Sep 2024 17:53:12 +0100 Subject: [PATCH] Fix symptom of handler missing persister --- cmd/http/main.go | 10 ++-------- internal/http/server.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/http/main.go b/cmd/http/main.go index 071cf00..7b085a8 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -16,7 +16,6 @@ import ( fsdb "git.defalsify.org/vise.git/db/fs" gdbmdb "git.defalsify.org/vise.git/db/gdbm" "git.defalsify.org/vise.git/engine" - "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/logging" @@ -113,12 +112,6 @@ func getResource(resourceDir string, ctx context.Context) (resource.Resource, er 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() { var dbDir string var resourceDir string @@ -196,7 +189,8 @@ func main() { defer stateStore.Close() 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{ Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))), Handler: sh, diff --git a/internal/http/server.go b/internal/http/server.go index eef41c9..7d1d8fe 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -10,6 +10,8 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" + + "git.grassecon.net/urdt/ussd/internal/handlers/ussd" ) var ( @@ -45,15 +47,18 @@ type SessionHandler struct { cfgTemplate engine.Config rp RequestParser rs resource.Resource - first resource.EntryFunc + //first resource.EntryFunc + hn *ussd.Handlers 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{ cfgTemplate: cfg, rs: rs, - first: first, + //first: first, + hn: hn, rp: rp, 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) return } + f.hn = f.hn.WithPersister(storage.Persister) defer f.provider.Put(cfg.SessionId, storage) en := getEngine(cfg, f.rs, storage.Persister) - en = en.WithFirst(f.first) + en = en.WithFirst(f.hn.Init) if cfg.EngineDebug { en = en.WithDebug(nil) }