Remove last internal package
This commit is contained in:
parent
c93a07832d
commit
2e0e854c4b
@ -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")
|
||||
)
|
||||
|
@ -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()
|
||||
}
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user