mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 08:37:13 +00:00
throw out unknown kinds
This commit is contained in:
parent
d5f2366ff8
commit
8c83d7333b
@ -103,7 +103,7 @@ func HandleKind(ctx context.Context, evt relay.Event, ws *websocket.Conn) {
|
|||||||
case evt.Kind >= 30000 && evt.Kind < 40000:
|
case evt.Kind >= 30000 && evt.Kind < 40000:
|
||||||
err = kinds.HandleParameterizedReplaceableKind(ctx, evt, collection, ws)
|
err = kinds.HandleParameterizedReplaceableKind(ctx, evt, collection, ws)
|
||||||
default:
|
default:
|
||||||
err = kinds.HandleUnknownKind(ctx, evt, collection)
|
err = kinds.HandleUnknownKind(ctx, evt, collection, ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package kinds
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
relay "grain/relay/types"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func HandleUnknownKind(ctx context.Context, evt relay.Event, collection *mongo.Collection) error {
|
|
||||||
_, err := collection.InsertOne(ctx, evt)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error inserting unknown event into MongoDB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Inserted unknown event into MongoDB:", evt.ID)
|
|
||||||
return nil
|
|
||||||
}
|
|
23
relay/handlers/kinds/unknown.go
Normal file
23
relay/handlers/kinds/unknown.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package kinds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
relay "grain/relay/types"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"golang.org/x/net/websocket"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleUnknownKind(ctx context.Context, evt relay.Event, collection *mongo.Collection, ws *websocket.Conn) error {
|
||||||
|
// Respond with an OK message indicating the event is not accepted
|
||||||
|
sendOK(ws, evt.ID, false, "kind is unknown and not accepted")
|
||||||
|
|
||||||
|
// Return nil as there's no error in the process, just that the event is not accepted
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user