grain/main.go

43 lines
909 B
Go
Raw Normal View History

2024-07-19 22:07:04 +00:00
package main
import (
"fmt"
"log"
"net/http"
2024-07-20 12:41:47 +00:00
"grain/server"
"grain/server/db"
"grain/server/events"
"grain/server/utils"
2024-07-19 22:07:04 +00:00
"golang.org/x/net/websocket"
)
func main() {
// Load configuration
config, err := utils.LoadConfig("config.yml")
if err != nil {
log.Fatal("Error loading config: ", err)
}
// Initialize MongoDB client
client, err := db.InitDB(config.MongoDB.URI, config.MongoDB.Database)
if err != nil {
log.Fatal("Error initializing database: ", err)
}
defer db.DisconnectDB(client)
2024-07-23 00:08:04 +00:00
// Initialize collections (dynamically handled in the events package)
events.SetClient(client)
2024-07-20 12:41:47 +00:00
server.SetClient(client)
// Start WebSocket server
2024-07-20 12:41:47 +00:00
http.Handle("/", websocket.Handler(server.Handler))
fmt.Println("WebSocket server started on", config.Server.Address)
err = http.ListenAndServe(config.Server.Address, nil)
if err != nil {
fmt.Println("Error starting server:", err)
}
2024-07-19 22:07:04 +00:00
}