mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-10-30 01:26:32 +00:00
25 lines
630 B
Go
25 lines
630 B
Go
// kinds/kind1.go
|
|
package kinds
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"grain/server/handlers/response"
|
|
relay "grain/server/types"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"golang.org/x/net/websocket"
|
|
)
|
|
|
|
func HandleKind1(ctx context.Context, evt relay.Event, collection *mongo.Collection, ws *websocket.Conn) error {
|
|
_, err := collection.InsertOne(ctx, evt)
|
|
if err != nil {
|
|
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)
|
|
response.SendOK(ws, evt.ID, true, "")
|
|
return nil
|
|
}
|