Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31d505d969 |
@@ -3,7 +3,7 @@ module git.grassecon.net/grassrootseconomics/visedriver
|
|||||||
go 1.23.0
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.defalsify.org/vise.git v0.3.2-0.20250407143413-e55cf9bcb7d2
|
git.defalsify.org/vise.git v0.2.3-0.20250204132233-2bffe532f21e
|
||||||
github.com/jackc/pgx/v5 v5.7.1
|
github.com/jackc/pgx/v5 v5.7.1
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
)
|
)
|
||||||
@@ -19,6 +19,7 @@ require (
|
|||||||
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect
|
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
github.com/stretchr/testify v1.9.0 // indirect
|
||||||
|
github.com/uptrace/bunrouter v1.0.23 // indirect
|
||||||
github.com/x448/float16 v0.8.4 // indirect
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
golang.org/x/crypto v0.27.0 // indirect
|
golang.org/x/crypto v0.27.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
git.defalsify.org/vise.git v0.2.3-0.20250204132233-2bffe532f21e h1:gtB9OdX6x5gQRM3W824dEurXuuf/YPInqgtv2KAp5Zo=
|
git.defalsify.org/vise.git v0.2.3-0.20250204132233-2bffe532f21e h1:gtB9OdX6x5gQRM3W824dEurXuuf/YPInqgtv2KAp5Zo=
|
||||||
git.defalsify.org/vise.git v0.2.3-0.20250204132233-2bffe532f21e/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
git.defalsify.org/vise.git v0.2.3-0.20250204132233-2bffe532f21e/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||||
git.defalsify.org/vise.git v0.3.2-0.20250407143413-e55cf9bcb7d2 h1:kbiDZtvphEKsTAnebrB6QxRbB7zdoTHSmzzumXrJ4hw=
|
|
||||||
git.defalsify.org/vise.git v0.3.2-0.20250407143413-e55cf9bcb7d2/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
|
||||||
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE=
|
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE=
|
||||||
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U=
|
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@@ -35,6 +33,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/uptrace/bunrouter v1.0.23 h1:Bi7NKw3uCQkcA/GUCtDNPq5LE5UdR9pe+UyWbjHB/wU=
|
||||||
|
github.com/uptrace/bunrouter v1.0.23/go.mod h1:O3jAcl+5qgnF+ejhgkmbceEk0E/mqaK+ADOocdNpY8M=
|
||||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||||
|
|||||||
+24
-7
@@ -7,6 +7,7 @@ import (
|
|||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/errors"
|
"git.grassecon.net/grassrootseconomics/visedriver/errors"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||||
|
"github.com/uptrace/bunrouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -16,6 +17,7 @@ var (
|
|||||||
// HTTPRequestHandler implements the session handler for HTTP
|
// HTTPRequestHandler implements the session handler for HTTP
|
||||||
type HTTPRequestHandler struct {
|
type HTTPRequestHandler struct {
|
||||||
request.RequestHandler
|
request.RequestHandler
|
||||||
|
router *bunrouter.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *HTTPRequestHandler) WriteError(w http.ResponseWriter, code int, err error) {
|
func (f *HTTPRequestHandler) WriteError(w http.ResponseWriter, code int, err error) {
|
||||||
@@ -30,12 +32,25 @@ func (f *HTTPRequestHandler) WriteError(w http.ResponseWriter, code int, err err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPRequestHandler(h request.RequestHandler) *HTTPRequestHandler {
|
func NewHTTPRequestHandler(h request.RequestHandler) *HTTPRequestHandler {
|
||||||
return &HTTPRequestHandler{
|
handler := &HTTPRequestHandler{
|
||||||
RequestHandler: h,
|
RequestHandler: h,
|
||||||
|
router: bunrouter.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Route all requests to existing vise logic
|
||||||
|
handler.router.GET("/*path", handler.handleViseRequest)
|
||||||
|
handler.router.POST("/*path", handler.handleViseRequest)
|
||||||
|
handler.router.PUT("/*path", handler.handleViseRequest)
|
||||||
|
handler.router.DELETE("/*path", handler.handleViseRequest)
|
||||||
|
|
||||||
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
hh.router.ServeHTTP(w, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hh *HTTPRequestHandler) handleViseRequest(w http.ResponseWriter, req bunrouter.Request) error {
|
||||||
var code int
|
var code int
|
||||||
var err error
|
var err error
|
||||||
var perr error
|
var perr error
|
||||||
@@ -47,17 +62,18 @@ func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
|||||||
|
|
||||||
rp := hh.GetRequestParser()
|
rp := hh.GetRequestParser()
|
||||||
cfg := hh.GetConfig()
|
cfg := hh.GetConfig()
|
||||||
cfg.SessionId, err = rp.GetSessionId(req.Context(), req)
|
cfg.SessionId, err = rp.GetSessionId(req.Context(), req.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
|
logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
|
||||||
hh.WriteError(w, 400, err)
|
hh.WriteError(w, 400, err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
rqs.Config = cfg
|
rqs.Config = cfg
|
||||||
rqs.Input, err = rp.GetInput(req)
|
rqs.Input, err = rp.GetInput(req.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
|
logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
|
||||||
hh.WriteError(w, 400, err)
|
hh.WriteError(w, 400, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rqs, err = hh.Process(rqs)
|
rqs, err = hh.Process(rqs)
|
||||||
@@ -74,7 +90,7 @@ func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
|||||||
|
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
hh.WriteError(w, 500, err)
|
hh.WriteError(w, 500, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
@@ -83,10 +99,11 @@ func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
|||||||
rqs, perr = hh.Reset(rqs.Ctx, rqs)
|
rqs, perr = hh.Reset(rqs.Ctx, rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hh.WriteError(w, 500, err)
|
hh.WriteError(w, 500, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
hh.WriteError(w, 500, perr)
|
hh.WriteError(w, 500, perr)
|
||||||
return
|
return perr
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,9 +99,7 @@ func TestRequestHandler_ServeHTTP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionHandler := &HTTPRequestHandler{
|
sessionHandler := NewHTTPRequestHandler(mockRequestHandler)
|
||||||
RequestHandler: mockRequestHandler,
|
|
||||||
}
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewBuffer(tt.input))
|
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewBuffer(tt.input))
|
||||||
req.Header.Set("X-Vise-Session", tt.sessionID)
|
req.Header.Set("X-Vise-Session", tt.sessionID)
|
||||||
@@ -119,7 +117,7 @@ func TestRequestHandler_ServeHTTP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRequestHandler_WriteError(t *testing.T) {
|
func TestRequestHandler_WriteError(t *testing.T) {
|
||||||
handler := &HTTPRequestHandler{}
|
handler := NewHTTPRequestHandler(&httpmocks.MockRequestHandler{})
|
||||||
mockWriter := &httpmocks.MockWriter{}
|
mockWriter := &httpmocks.MockWriter{}
|
||||||
err := errors.New("test error")
|
err := errors.New("test error")
|
||||||
|
|
||||||
|
|||||||
@@ -90,10 +90,6 @@ func (tdb *ThreadGdbmDb) Prefix() uint8 {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tdb *ThreadGdbmDb) Base() *db.DbBase {
|
|
||||||
return tdb.Base()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tdb *ThreadGdbmDb) SetLock(typ uint8, locked bool) error {
|
func (tdb *ThreadGdbmDb) SetLock(typ uint8, locked bool) error {
|
||||||
tdb.reserve()
|
tdb.reserve()
|
||||||
err := tdb.db.SetLock(typ, locked)
|
err := tdb.db.SetLock(typ, locked)
|
||||||
|
|||||||
@@ -203,20 +203,6 @@ func (ms *MenuStorageService) GetUserdataDb(ctx context.Context) (db.Db, error)
|
|||||||
return userStore, nil
|
return userStore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *MenuStorageService) GetLogDb(ctx context.Context, mainDb db.Db, connStr string, section string) (db.Db, error) {
|
|
||||||
err := ms.ensureDbDir(connStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
connStr = path.Join(connStr, section)
|
|
||||||
tgdbm := gdbmstorage.NewThreadGdbmDb()
|
|
||||||
err = tgdbm.Connect(ctx, connStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return tgdbm, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ms *MenuStorageService) GetResource(ctx context.Context) (resource.Resource, error) {
|
func (ms *MenuStorageService) GetResource(ctx context.Context) (resource.Resource, error) {
|
||||||
store, err := ms.getOrCreateDb(ctx, "resource.gdbm", STORETYPE_RESOURCE)
|
store, err := ms.getOrCreateDb(ctx, "resource.gdbm", STORETYPE_RESOURCE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user