From 840c22ca8998f0ecfcb561d8ec84ed679221f851 Mon Sep 17 00:00:00 2001 From: lash Date: Sat, 11 Jan 2025 08:01:48 +0000 Subject: [PATCH] Factor out session handler, introduce entry handler --- entry/handlers.go | 10 +++++ request/request.go | 1 + {handlers => session}/base.go | 77 +++-------------------------------- 3 files changed, 17 insertions(+), 71 deletions(-) create mode 100644 entry/handlers.go rename {handlers => session}/base.go (55%) diff --git a/entry/handlers.go b/entry/handlers.go new file mode 100644 index 0000000..bceb074 --- /dev/null +++ b/entry/handlers.go @@ -0,0 +1,10 @@ +package entry + +import ( + "git.defalsify.org/vise.git/persist" +) + +type EntryHandler interface { + Init(context.Context, string, []byte) (*resource.Result, error) // HandlerFunc + Exit() +} diff --git a/request/request.go b/request/request.go index 2963f09..7d7654a 100644 --- a/request/request.go +++ b/request/request.go @@ -43,6 +43,7 @@ type RequestHandler interface { Reset(rs RequestSession) (RequestSession, error) Shutdown() } + type SessionHandler struct { RequestHandler } diff --git a/handlers/base.go b/session/base.go similarity index 55% rename from handlers/base.go rename to session/base.go index d5b2d63..88a127a 100644 --- a/handlers/base.go +++ b/session/base.go @@ -1,95 +1,30 @@ -package handlers +package session import ( - "context" - "fmt" - - "git.defalsify.org/vise.git/asm" "git.defalsify.org/vise.git/db" - "git.defalsify.org/vise.git/state" - "git.defalsify.org/vise.git/cache" "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/logging" - + "git.grassecon.net/grassrootseconomics/visedriver/handlers" "git.grassecon.net/grassrootseconomics/visedriver/request" - "git.grassecon.net/grassrootseconomics/visedriver/errors" - dbstorage "git.grassecon.net/grassrootseconomics/visedriver/storage/db" - "git.grassecon.net/grassrootseconomics/visedriver/common" "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/remote" - "git.grassecon.net/grassrootseconomics/visedriver/models" - "git.grassecon.net/grassrootseconomics/visedriver/utils" + "git.grassecon.net/grassrootseconomics/visedriver/errors" ) var ( - logg = logging.NewVanilla().WithDomain("handlers") + logg = logging.NewVanilla().WithDomain("visedriver.session") ) -type Handlers struct { - pe *persist.Persister - st *state.State - ca cache.Memory - userdataStore common.DataStore - adminstore *utils.AdminStore - flagManager *asm.FlagParser - accountService remote.AccountServiceInterface - prefixDb dbstorage.PrefixDb - profile *models.Profile - ReplaceSeparatorFunc func(string) string -} - -// NewHandlers creates a new instance of the Handlers struct with the provided dependencies. -func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface, replaceSeparatorFunc func(string) string) (*Handlers, error) { - if userdataStore == nil { - return nil, fmt.Errorf("cannot create handler with nil userdata store") - } - userDb := &common.UserDataStore{ - Db: userdataStore, - } - - // Instantiate the SubPrefixDb with "DATATYPE_USERDATA" prefix - prefix := common.ToBytes(db.DATATYPE_USERDATA) - prefixDb := dbstorage.NewSubPrefixDb(userdataStore, prefix) - - h := &Handlers{ - userdataStore: userDb, - flagManager: appFlags, - adminstore: adminstore, - accountService: accountService, - prefixDb: prefixDb, - profile: &models.Profile{Max: 6}, - ReplaceSeparatorFunc: replaceSeparatorFunc, - } - return h, nil -} - -func (h *Handlers) Exit() { - h.pe = nil -} - -func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource.Result, error) { - return resource.Result{}, nil -} - -// WithPersister sets persister instance to the handlers. -func (h *Handlers) WithPersister(pe *persist.Persister) *Handlers { - if h.pe != nil { - panic("persister already set") - } - h.pe = pe - return h -} type BaseSessionHandler struct { cfgTemplate engine.Config rp request.RequestParser rs resource.Resource - hn *Handlers + hn *handlers.Handlers provider storage.StorageProvider } -func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *Handlers) *BaseSessionHandler { +func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseSessionHandler { return &BaseSessionHandler{ cfgTemplate: cfg, rs: rs,