From 4accb847b93e4c223d499b5a3964405eb39dace7 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 6 Sep 2024 03:05:18 +0100 Subject: [PATCH] Successfully executed account regisration using http --- cmd/http/main.go | 18 ++++++++++-------- internal/http/server.go | 16 +++++++++++++--- internal/http/storage.go | 8 ++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cmd/http/main.go b/cmd/http/main.go index 4a52b7b..d253c12 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -118,13 +118,15 @@ func main() { var resourceDir string var size uint var sessionId string - var debug bool + var engineDebug bool + var stateDebug bool var host string var port uint flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from") flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") - flag.BoolVar(&debug, "d", false, "use engine debug output") + flag.BoolVar(&engineDebug, "engine-debug", false, "use engine debug output") + flag.BoolVar(&stateDebug, "state-debug", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&host, "h", "127.0.0.1", "http host") flag.UintVar(&port, "p", 7123, "http port") @@ -147,18 +149,18 @@ func main() { OutputSize: uint32(size), FlagCount: uint32(16), } + if stateDebug { + cfg.StateDebug = true + } + if engineDebug { + cfg.EngineDebug = true + } rs, err := getResource(resourceDir, ctx) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } -// -// pr, err := getPersister(dbDir, ctx) -// if err != nil { -// fmt.Fprintf(os.Stderr, err.Error()) -// os.Exit(1) -// } userdataStore := getUserdataDb(dbDir, ctx) if err != nil { diff --git a/internal/http/server.go b/internal/http/server.go index e8ae9c3..aa53448 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -7,10 +7,15 @@ import ( "git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" ) +var ( + logg = logging.NewVanilla().WithDomain("httpserver") +) + type RequestParser struct { } @@ -77,6 +82,8 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { cfg := f.cfgTemplate cfg.SessionId = sessionId + logg.InfoCtxf(ctx, "new request", "session", cfg.SessionId, "input", input) + storage, err := f.provider.Get(cfg.SessionId) if err != nil { f.writeError(w, 500, "Storage retrieval fail", err) @@ -88,9 +95,12 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { en = en.WithDebug(nil) } - if len(input) == 0 { - r, err = en.Init(ctx) - } else { + r, err = en.Init(ctx) + if err != nil { + f.writeError(w, 500, "Engine init fail", err) + return + } + if r && len(input) > 0 { r, err = en.Exec(ctx, input) } if err != nil { diff --git a/internal/http/storage.go b/internal/http/storage.go index eb17f92..012c56c 100644 --- a/internal/http/storage.go +++ b/internal/http/storage.go @@ -30,14 +30,14 @@ func NewSimpleStorageProvider(stateStore db.Db, userdataStore db.Db) StorageProv } } -func (*SimpleStorageProvider) Get(sessionId string) (Storage, error) { - return Storage{}, nil +func (p *SimpleStorageProvider) Get(sessionId string) (Storage, error) { + return p.Storage, nil } -func (*SimpleStorageProvider) Put(sessionId string, storage Storage) error { +func (p *SimpleStorageProvider) Put(sessionId string, storage Storage) error { return nil } -func (*SimpleStorageProvider) Close() error { +func (p *SimpleStorageProvider) Close() error { return nil }