-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (52 loc) · 1.67 KB
/
main.go
File metadata and controls
64 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"log"
"os"
"eric-sims/quipnotes/docs"
"eric-sims/quipnotes/internal/game"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title quipNotes Server
// @version 1.0
// @description This handles the game logic and communication
// @host localhost:8081
func main() {
game.Game = game.NewGameManager()
err := godotenv.Load()
if err != nil {
panic(fmt.Sprintf("Error loading .env file: %s", err.Error()))
}
filePath := os.Getenv("WORDS_FILE_PATH")
fmt.Println("filePath", filePath)
if err := game.LoadWordsFromCSV(filePath); err != nil {
panic(fmt.Sprintf("Failed to load words.csv: %s", err.Error()))
}
r := gin.Default()
// CORS setup - allow only specific origins
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"}, // Your frontend's URL
AllowMethods: []string{"GET", "POST", "DELETE"}, // Allowed HTTP methods
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
r.POST("/players", game.AddPlayer)
r.DELETE("/players/:id", game.DeletePlayer)
r.GET("/players/:id/tiles", game.GetTiles)
r.POST("/game/draw", game.DrawTiles)
r.POST("/game/submit", game.SubmitNote)
r.GET("/game/submitted-notes", game.GetSubmittedNotes)
r.DELETE("/game/submitted-notes", game.DeleteSubmittedNotes)
docs.SwaggerInfo.BasePath = ""
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
log.Println("Starting server...")
err = r.Run(":8081")
if err != nil {
panic(err)
}
}