mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-10-30 01:26:32 +00:00
Adds database and collections if non exists, renamed project
This commit is contained in:
parent
26fec6e371
commit
4a92b0ad25
15
main.go
15
main.go
@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
@ -118,6 +119,20 @@ func main() {
|
|||||||
eventKind0Collection = client.Database("grain").Collection("event-kind0")
|
eventKind0Collection = client.Database("grain").Collection("event-kind0")
|
||||||
eventKind1Collection = client.Database("grain").Collection("event-kind1")
|
eventKind1Collection = client.Database("grain").Collection("event-kind1")
|
||||||
|
|
||||||
|
// Ensure collections exist by creating an index (which will implicitly create the collections)
|
||||||
|
indexModel := mongo.IndexModel{
|
||||||
|
Keys: bson.D{{Key: "id", Value: 1}},
|
||||||
|
Options: options.Index().SetUnique(true),
|
||||||
|
}
|
||||||
|
_, err = eventKind0Collection.Indexes().CreateOne(context.TODO(), indexModel)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to create index on event-kind0: ", err)
|
||||||
|
}
|
||||||
|
_, err = eventKind1Collection.Indexes().CreateOne(context.TODO(), indexModel)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to create index on event-kind1: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Start WebSocket server
|
// Start WebSocket server
|
||||||
http.Handle("/", websocket.Handler(handler))
|
http.Handle("/", websocket.Handler(handler))
|
||||||
fmt.Println("WebSocket server started on :8080")
|
fmt.Println("WebSocket server started on :8080")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# GRAIN 🌾 WIP
|
# GRAIN 🌾 WIP
|
||||||
|
|
||||||
**Go Relay and Information Network**
|
**Go Relay Archetecture for Implementing Nostr**
|
||||||
|
|
||||||
GRAIN is an open-source Nostr relay implementation written in Go. This project aims to provide a robust and efficient Nostr relay that supports the NIP-01 protocol, focusing on processing user metadata and text notes.
|
GRAIN is an open-source Nostr relay implementation written in Go. This project aims to provide a robust and efficient Nostr relay that supports the NIP-01 protocol, focusing on processing user metadata and text notes.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user