diff --git a/errors/errors.go b/errors/errors.go index 40974b1..6bcb9ce 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -1,15 +1,15 @@ package errors import ( - "git.grassecon.net/grassrootseconomics/visedriver/internal/handlers" + "errors" ) var ( - ErrInvalidRequest = handlers.ErrInvalidRequest - ErrSessionMissing = handlers.ErrSessionMissing - ErrInvalidInput = handlers.ErrInvalidInput - ErrStorage = handlers.ErrStorage - ErrEngineType = handlers.ErrEngineType - ErrEngineInit = handlers.ErrEngineInit - ErrEngineExec = handlers.ErrEngineExec + ErrInvalidRequest = errors.New("invalid request for context") + ErrSessionMissing = errors.New("missing session") + ErrInvalidInput = errors.New("invalid input") + ErrStorage = errors.New("storage retrieval fail") + ErrEngineType = errors.New("incompatible engine") + ErrEngineInit = errors.New("engine init fail") + ErrEngineExec = errors.New("engine exec fail") ) diff --git a/internal/handlers/single.go b/internal/handlers/single.go deleted file mode 100644 index 6ce7081..0000000 --- a/internal/handlers/single.go +++ /dev/null @@ -1,54 +0,0 @@ -package handlers - -import ( - "context" - "errors" - "io" - - "git.defalsify.org/vise.git/engine" - "git.defalsify.org/vise.git/logging" - "git.defalsify.org/vise.git/persist" - "git.defalsify.org/vise.git/resource" - - "git.grassecon.net/grassrootseconomics/visedriver/storage" -) - -var ( - logg = logging.NewVanilla().WithDomain("handlers") -) - -var ( - ErrInvalidRequest = errors.New("invalid request for context") - ErrSessionMissing = errors.New("missing session") - ErrInvalidInput = errors.New("invalid input") - ErrStorage = errors.New("storage retrieval fail") - ErrEngineType = errors.New("incompatible engine") - ErrEngineInit = errors.New("engine init fail") - ErrEngineExec = errors.New("engine exec fail") -) - -type RequestSession struct { - Ctx context.Context - Config engine.Config - Engine engine.Engine - Input []byte - Storage *storage.Storage - Writer io.Writer - Continue bool -} - -// TODO: seems like can remove this. -type RequestParser interface { - GetSessionId(context context.Context, rq any) (string, error) - GetInput(rq any) ([]byte, error) -} - -type RequestHandler interface { - GetConfig() engine.Config - GetRequestParser() RequestParser - GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine - Process(rs RequestSession) (RequestSession, error) - Output(rs RequestSession) (RequestSession, error) - Reset(rs RequestSession) (RequestSession, error) - Shutdown() -} diff --git a/session/http/parse.go b/session/http/parse.go index c942242..83cbf77 100644 --- a/session/http/parse.go +++ b/session/http/parse.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "net/http" - "git.grassecon.net/grassrootseconomics/visedriver/internal/handlers" + "git.grassecon.net/grassrootseconomics/visedriver/errors" ) type DefaultRequestParser struct { @@ -14,11 +14,11 @@ type DefaultRequestParser struct { func (rp *DefaultRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) { rqv, ok := rq.(*http.Request) if !ok { - return "", handlers.ErrInvalidRequest + return "", errors.ErrInvalidRequest } v := rqv.Header.Get("X-Vise-Session") if v == "" { - return "", handlers.ErrSessionMissing + return "", errors.ErrSessionMissing } return v, nil } @@ -26,7 +26,7 @@ func (rp *DefaultRequestParser) GetSessionId(ctx context.Context, rq any) (strin func (rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) { rqv, ok := rq.(*http.Request) if !ok { - return nil, handlers.ErrInvalidRequest + return nil, errors.ErrInvalidRequest } defer rqv.Body.Close() v, err := ioutil.ReadAll(rqv.Body) diff --git a/session/http/server_test.go b/session/http/server_test.go index e2b3c49..2987c24 100644 --- a/session/http/server_test.go +++ b/session/http/server_test.go @@ -9,7 +9,7 @@ import ( "testing" "git.defalsify.org/vise.git/engine" - "git.grassecon.net/grassrootseconomics/visedriver/internal/handlers" + viseerrors "git.grassecon.net/grassrootseconomics/visedriver/errors" "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks/httpmocks" "git.grassecon.net/grassrootseconomics/visedriver/request" ) @@ -44,14 +44,14 @@ func TestSessionHandler_ServeHTTP(t *testing.T) { { name: "Missing Session ID", sessionID: "", - parserErr: handlers.ErrSessionMissing, + parserErr: viseerrors.ErrSessionMissing, expectedStatus: http.StatusBadRequest, }, { name: "Process Error", sessionID: "123", input: []byte("test input"), - processErr: handlers.ErrStorage, + processErr: viseerrors.ErrStorage, expectedStatus: http.StatusInternalServerError, }, { @@ -151,13 +151,13 @@ func TestDefaultRequestParser_GetSessionId(t *testing.T) { name: "Missing Session ID", request: httptest.NewRequest(http.MethodPost, "/", nil), expectedID: "", - expectedError: handlers.ErrSessionMissing, + expectedError: viseerrors.ErrSessionMissing, }, { name: "Invalid Request Type", request: invalidRequestType{}, expectedID: "", - expectedError: handlers.ErrInvalidRequest, + expectedError: viseerrors.ErrInvalidRequest, }, } @@ -203,7 +203,7 @@ func TestDefaultRequestParser_GetInput(t *testing.T) { name: "Invalid Request Type", request: invalidRequestType{}, expectedInput: nil, - expectedError: handlers.ErrInvalidRequest, + expectedError: viseerrors.ErrInvalidRequest, }, { name: "Read Error",