-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (39 loc) · 1.08 KB
/
main.go
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
package main
import (
"delyan-kirov/sudoku/data"
"delyan-kirov/sudoku/sudoku"
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
// Serve static files from the build directory
r.Static("/static", "./build/static")
r.GET("/", func(c *gin.Context) {
c.File("./build/index.html")
})
r.POST("/check_solution", func(c *gin.Context) {
var jsonData [9][9]int
if err := c.ShouldBindJSON(&jsonData); err != nil {
c.JSON(400, gin.H{"error": "Invalid JSON format"})
fmt.Printf("Error parsing JSON: %v\n", err)
return
}
sudoku_board := sudoku.Sudoku(jsonData)
sudoku.PrintSudoku(sudoku_board)
responseData := gin.H{"message": "Solution checked successfully", "checkedSolution": "example"}
c.JSON(200, responseData)
})
r.GET("/initial_board", func(c *gin.Context) {
initialBoard, err := data.Read(32)
if err != nil {
fmt.Println("Could not read the sudoku")
fmt.Printf("ERROR: %s\n", err)
c.JSON(500, gin.H{"error": "Internal Server Error"})
return
}
c.JSON(200, gin.H{"initialBoard": initialBoard})
})
port := ":8080"
r.Run(port)
}