Remove last internal package
This commit is contained in:
parent
c93a07832d
commit
2e0e854c4b
@ -1,15 +1,15 @@
|
|||||||
package errors
|
package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/internal/handlers"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidRequest = handlers.ErrInvalidRequest
|
ErrInvalidRequest = errors.New("invalid request for context")
|
||||||
ErrSessionMissing = handlers.ErrSessionMissing
|
ErrSessionMissing = errors.New("missing session")
|
||||||
ErrInvalidInput = handlers.ErrInvalidInput
|
ErrInvalidInput = errors.New("invalid input")
|
||||||
ErrStorage = handlers.ErrStorage
|
ErrStorage = errors.New("storage retrieval fail")
|
||||||
ErrEngineType = handlers.ErrEngineType
|
ErrEngineType = errors.New("incompatible engine")
|
||||||
ErrEngineInit = handlers.ErrEngineInit
|
ErrEngineInit = errors.New("engine init fail")
|
||||||
ErrEngineExec = handlers.ErrEngineExec
|
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"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/internal/handlers"
|
"git.grassecon.net/grassrootseconomics/visedriver/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DefaultRequestParser struct {
|
type DefaultRequestParser struct {
|
||||||
@ -14,11 +14,11 @@ type DefaultRequestParser struct {
|
|||||||
func (rp *DefaultRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) {
|
func (rp *DefaultRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) {
|
||||||
rqv, ok := rq.(*http.Request)
|
rqv, ok := rq.(*http.Request)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", handlers.ErrInvalidRequest
|
return "", errors.ErrInvalidRequest
|
||||||
}
|
}
|
||||||
v := rqv.Header.Get("X-Vise-Session")
|
v := rqv.Header.Get("X-Vise-Session")
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return "", handlers.ErrSessionMissing
|
return "", errors.ErrSessionMissing
|
||||||
}
|
}
|
||||||
return v, nil
|
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) {
|
func (rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) {
|
||||||
rqv, ok := rq.(*http.Request)
|
rqv, ok := rq.(*http.Request)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, handlers.ErrInvalidRequest
|
return nil, errors.ErrInvalidRequest
|
||||||
}
|
}
|
||||||
defer rqv.Body.Close()
|
defer rqv.Body.Close()
|
||||||
v, err := ioutil.ReadAll(rqv.Body)
|
v, err := ioutil.ReadAll(rqv.Body)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/engine"
|
"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/testutil/mocks/httpmocks"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||||
)
|
)
|
||||||
@ -44,14 +44,14 @@ func TestSessionHandler_ServeHTTP(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Missing Session ID",
|
name: "Missing Session ID",
|
||||||
sessionID: "",
|
sessionID: "",
|
||||||
parserErr: handlers.ErrSessionMissing,
|
parserErr: viseerrors.ErrSessionMissing,
|
||||||
expectedStatus: http.StatusBadRequest,
|
expectedStatus: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Process Error",
|
name: "Process Error",
|
||||||
sessionID: "123",
|
sessionID: "123",
|
||||||
input: []byte("test input"),
|
input: []byte("test input"),
|
||||||
processErr: handlers.ErrStorage,
|
processErr: viseerrors.ErrStorage,
|
||||||
expectedStatus: http.StatusInternalServerError,
|
expectedStatus: http.StatusInternalServerError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -151,13 +151,13 @@ func TestDefaultRequestParser_GetSessionId(t *testing.T) {
|
|||||||
name: "Missing Session ID",
|
name: "Missing Session ID",
|
||||||
request: httptest.NewRequest(http.MethodPost, "/", nil),
|
request: httptest.NewRequest(http.MethodPost, "/", nil),
|
||||||
expectedID: "",
|
expectedID: "",
|
||||||
expectedError: handlers.ErrSessionMissing,
|
expectedError: viseerrors.ErrSessionMissing,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid Request Type",
|
name: "Invalid Request Type",
|
||||||
request: invalidRequestType{},
|
request: invalidRequestType{},
|
||||||
expectedID: "",
|
expectedID: "",
|
||||||
expectedError: handlers.ErrInvalidRequest,
|
expectedError: viseerrors.ErrInvalidRequest,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ func TestDefaultRequestParser_GetInput(t *testing.T) {
|
|||||||
name: "Invalid Request Type",
|
name: "Invalid Request Type",
|
||||||
request: invalidRequestType{},
|
request: invalidRequestType{},
|
||||||
expectedInput: nil,
|
expectedInput: nil,
|
||||||
expectedError: handlers.ErrInvalidRequest,
|
expectedError: viseerrors.ErrInvalidRequest,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Read Error",
|
name: "Read Error",
|
||||||
|
Loading…
Reference in New Issue
Block a user