Add new debug option for http

This commit is contained in:
Tom Wiesing 2023-11-22 17:28:46 +01:00
parent 0ba34fe80f
commit 0290a42d07
No known key found for this signature in database
39 changed files with 293 additions and 189 deletions

View file

@ -10,8 +10,7 @@ import (
"time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
"github.com/gorilla/websocket"
"github.com/tkw1536/pkglib/httpx"
"github.com/tkw1536/pkglib/httpx/websocket"
)
// ActionMap handles a set of WebSocket actions
@ -40,7 +39,7 @@ func (err errPanic) Error() string {
// Finally it will send a ResultMessage once handling is complete.
//
// A corresponding client implementation of this can be found in ..../remote/proto.ts
func (am ActionMap) Handle(auth *auth.Auth, conn httpx.WebSocketConnection) (name string, err error) {
func (am ActionMap) Handle(auth *auth.Auth, conn *websocket.Connection) (name string, err error) {
var wg sync.WaitGroup
// once we have finished executing send a binary message (indicating success) to the client.
@ -67,7 +66,7 @@ func (am ActionMap) Handle(auth *auth.Auth, conn httpx.WebSocketConnection) (nam
}
// encode the result message to json!
var message httpx.WebSocketMessage
var message websocket.Message
message.Type = websocket.BinaryMessage
message.Bytes, err = json.Marshal(result)

View file

@ -14,7 +14,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/admin/socket/actions"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/admin/socket/proto"
"github.com/rs/zerolog"
"github.com/tkw1536/pkglib/httpx"
"github.com/tkw1536/pkglib/httpx/websocket"
"github.com/tkw1536/pkglib/lazy"
)
@ -48,14 +48,14 @@ func (socket *Sockets) Routes() component.Routes {
}
func (sockets *Sockets) HandleRoute(ctx context.Context, path string) (http.Handler, error) {
return &httpx.WebSocket{
return &websocket.Server{
Context: ctx,
Handler: sockets.Serve,
}, nil
}
// Serve handles a connection to the websocket api
func (socket *Sockets) Serve(conn httpx.WebSocketConnection) {
func (socket *Sockets) Serve(conn *websocket.Connection) {
// handle the websocket connection!
name, err := socket.actions.Get(func() proto.ActionMap { return socket.Actions(conn.Context()) }).Handle(socket.dependencies.Auth, conn)
if err != nil {