forked from Deveshjoshi101/deploy-game
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (43 loc) · 970 Bytes
/
main.go
File metadata and controls
52 lines (43 loc) · 970 Bytes
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
package main
import (
"github.com/gin-gonic/gin"
// "net/http"
// "fmt"
"strconv"
)
var router *gin.Engine
var bestScore = 999999.0
func main() {
router = gin.Default()
// router.LoadHTMLGlob("index.html")
initializeRoutes()
router.Run(":8080")
}
func initializeRoutes() {
// router.POST("/setbs", handleSet)
router.GET("/setbs/:hs", handleSet)
router.GET("/getbs", handleGet)
}
func handleGet(c *gin.Context) {
// message, _ := c.GetQuery("m")
bsString := strconv.FormatFloat(bestScore, 'e', -1, 64)
// c.String(http.StatusOK, bsString)
c.JSONP(200, gin.H{
"hs": bsString,
})
}
func handleSet(c *gin.Context) {
// message, _ := c.GetQuery("hs")
// // c.String(http.StatusOK, string(bestScore))
// bs, _ := strconv.ParseFloat(message, 64)
// bestScore := bs
// fmt.Println(bestScore)
// c.JSONP(200, gin.H{
// "hs": message,
// })
hs := c.Param("hs")
bestScore, _ = strconv.ParseFloat(hs, 64)
c.JSONP(200, gin.H{
"hs": hs,
})
}