From 1e9c9cf6ad5e9fa5642c784f41184f7583eb3dde Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Sat, 14 Sep 2024 15:57:16 +0300 Subject: [PATCH] removed AT specific code --- internal/handlers/base.go | 21 --------------------- internal/handlers/single.go | 1 - internal/http/server.go | 34 +++++++--------------------------- 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/internal/handlers/base.go b/internal/handlers/base.go index 054654b..53df2c0 100644 --- a/internal/handlers/base.go +++ b/internal/handlers/base.go @@ -1,8 +1,6 @@ package handlers import ( - "io" - "git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/persist" @@ -90,25 +88,6 @@ func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession, error) return rqs, err } -func (f *BaseSessionHandler) AtOutput(rqs RequestSession) (RequestSession, error) { - var err error - var prefix string - - if rqs.Continue { - prefix = "CON " - } else { - prefix = "END " - } - - _, err = io.WriteString(rqs.Writer, prefix) - if err != nil { - return rqs, err - } - - _, err = rqs.Engine.WriteResult(rqs.Ctx, rqs.Writer) - return rqs, err -} - func(f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) { defer f.provider.Put(rqs.Config.SessionId, rqs.Storage) return rqs, rqs.Engine.Finish() diff --git a/internal/handlers/single.go b/internal/handlers/single.go index a900c14..69a4d1e 100644 --- a/internal/handlers/single.go +++ b/internal/handlers/single.go @@ -51,7 +51,6 @@ type RequestHandler interface { GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine Process(rs RequestSession) (RequestSession, error) Output(rs RequestSession) (RequestSession, error) - AtOutput(rs RequestSession) (RequestSession, error) Reset(rs RequestSession) (RequestSession, error) Shutdown() } diff --git a/internal/http/server.go b/internal/http/server.go index 964d23b..3ea0159 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -43,30 +43,14 @@ func(rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) { return v, nil } - - -type SessionHandlerOption func(*SessionHandler) - -func WithAtOutput() SessionHandlerOption { - return func(sh *SessionHandler) { - sh.useAtOutput = true - } -} - type SessionHandler struct { handlers.RequestHandler - useAtOutput bool } -func ToSessionHandler(h handlers.RequestHandler, opts ...SessionHandlerOption) *SessionHandler { - sh := &SessionHandler{ +func ToSessionHandler(h handlers.RequestHandler) *SessionHandler { + return &SessionHandler{ RequestHandler: h, - useAtOutput: false, } - for _, opt := range opts { - opt(sh) - } - return sh } func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) { @@ -84,6 +68,7 @@ func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) { func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var code int var err error + var perr error rqs := handlers.RequestSession{ Ctx: req.Context(), @@ -124,19 +109,14 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { w.WriteHeader(200) w.Header().Set("Content-Type", "text/plain") - if f.useAtOutput { - rqs, err = f.AtOutput(rqs) - } else { - rqs, err = f.Output(rqs) - } + rqs, err = f.Output(rqs) + rqs, perr = f.Reset(rqs) if err != nil { f.writeError(w, 500, err) return } - - rqs, err = f.Reset(rqs) - if err != nil { - f.writeError(w, 500, err) + if perr != nil { + f.writeError(w, 500, perr) return } }