1
- package main
1
+ package server
2
2
3
3
import (
4
+ "decksframework/db"
4
5
"decksframework/decks"
5
6
"fmt"
6
7
"github.com/gin-gonic/gin"
@@ -16,16 +17,14 @@ Notes: Please branch out server routes into separate handler files when adding n
16
17
Single file for now
17
18
*/
18
19
19
- var router * gin.Engine
20
-
21
- func startApiServer (port string , debug bool ) {
20
+ func StartApiServer (port string , debug bool ) {
22
21
if debug == false {
23
22
gin .SetMode ("release" )
24
23
}
25
24
26
- router = gin .Default ()
25
+ router : = gin .Default ()
27
26
28
- initializeRoutes ( )
27
+ InitializeRoutes ( router )
29
28
30
29
// listen and serve
31
30
err := router .Run (":" + port )
@@ -34,8 +33,10 @@ func startApiServer(port string, debug bool) {
34
33
}
35
34
}
36
35
37
- func initializeRoutes () {
38
- router .POST ("/deck/create" , func (c * gin.Context ) {
36
+ func InitializeRoutes (r * gin.Engine ) {
37
+ deckStore := db .GetDeckStore ()
38
+
39
+ r .POST ("/deck/create" , func (c * gin.Context ) {
39
40
shouldShuffleDeck := false
40
41
41
42
// ?shouldShuffleDeck=true for deck shuffling
@@ -72,7 +73,7 @@ func initializeRoutes() {
72
73
c .JSON (http .StatusCreated , deck .GetClosedDeck ())
73
74
})
74
75
75
- router .POST ("/deck/draw" , func (c * gin.Context ) {
76
+ r .POST ("/deck/draw" , func (c * gin.Context ) {
76
77
uuid , ok := c .GetQuery ("uuid" )
77
78
if ! ok || uuid == "" {
78
79
c .AbortWithStatusJSON (http .StatusBadRequest , ErrorMsg ("uuid required" ))
@@ -107,7 +108,7 @@ func initializeRoutes() {
107
108
})
108
109
})
109
110
110
- router .GET ("/deck/open" , func (c * gin.Context ) {
111
+ r .GET ("/deck/open" , func (c * gin.Context ) {
111
112
uuid , ok := c .GetQuery ("uuid" )
112
113
if ! ok || uuid == "" {
113
114
c .AbortWithStatusJSON (http .StatusBadRequest , ErrorMsg ("uuid required" ))
0 commit comments