From 0dd29c5bcb44f0eb4e483cf2f708632de0990701 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Wed, 24 Jul 2024 17:00:59 -0400 Subject: [PATCH] sendOK refactored, moved to own file --- relay/handlers/event.go | 12 ++++-------- relay/handlers/ok.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 relay/handlers/ok.go diff --git a/relay/handlers/event.go b/relay/handlers/event.go index 63c91cd..13be0d9 100644 --- a/relay/handlers/event.go +++ b/relay/handlers/event.go @@ -45,7 +45,7 @@ func HandleEvent(ws *websocket.Conn, message []interface{}) { func HandleKind(ctx context.Context, evt relay.Event, ws *websocket.Conn) { if !utils.CheckSignature(evt) { - OKResponse(ws, evt.ID, false, "invalid: signature verification failed") + sendOK(ws, evt.ID, false, "invalid: signature verification failed") return } @@ -77,15 +77,11 @@ func HandleKind(ctx context.Context, evt relay.Event, ws *websocket.Conn) { } if err != nil { - OKResponse(ws, evt.ID, false, fmt.Sprintf("error: %v", err)) + sendOK(ws, evt.ID, false, fmt.Sprintf("error: %v", err)) return } - OKResponse(ws, evt.ID, true, "") + sendOK(ws, evt.ID, true, "") } -func OKResponse(ws *websocket.Conn, eventID string, status bool, message string) { - response := []interface{}{"OK", eventID, status, message} - responseBytes, _ := json.Marshal(response) - websocket.Message.Send(ws, string(responseBytes)) -} + diff --git a/relay/handlers/ok.go b/relay/handlers/ok.go new file mode 100644 index 0000000..c4151a6 --- /dev/null +++ b/relay/handlers/ok.go @@ -0,0 +1,13 @@ +package handlers + +import ( + "encoding/json" + + "golang.org/x/net/websocket" +) + +func sendOK(ws *websocket.Conn, eventID string, status bool, message string) { + response := []interface{}{"OK", eventID, status, message} + responseBytes, _ := json.Marshal(response) + websocket.Message.Send(ws, string(responseBytes)) +} \ No newline at end of file