grain/relay/handlers/kinds/kind1.go

25 lines
628 B
Go
Raw Normal View History

2024-07-27 14:06:34 +00:00
// kinds/kind1.go
2024-07-23 17:22:55 +00:00
package kinds
import (
"context"
"fmt"
2024-07-27 14:06:34 +00:00
"grain/relay/handlers/response"
2024-07-23 17:30:29 +00:00
relay "grain/relay/types"
"go.mongodb.org/mongo-driver/mongo"
2024-07-27 14:06:34 +00:00
"golang.org/x/net/websocket"
)
2024-07-27 14:06:34 +00:00
func HandleKind1(ctx context.Context, evt relay.Event, collection *mongo.Collection, ws *websocket.Conn) error {
_, err := collection.InsertOne(ctx, evt)
if err != nil {
2024-07-27 14:06:34 +00:00
response.SendOK(ws, evt.ID, false, "error: could not connect to the database")
return fmt.Errorf("error inserting event into MongoDB: %v", err)
}
fmt.Println("Inserted event kind 1 into MongoDB:", evt.ID)
2024-07-27 14:06:34 +00:00
response.SendOK(ws, evt.ID, true, "")
return nil
}