-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from atul24112001/feature/fiber
Feature/fiber
- Loading branch information
Showing
29 changed files
with
587 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env | ||
errors.txt | ||
errors.txt | ||
flappy-bird-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package admin | ||
|
||
import ( | ||
gameManager "flappy-bird-server/game-manager" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type Game struct { | ||
Id string `json:"id"` | ||
Status string `json:"status"` | ||
Users []string `json:"users"` | ||
} | ||
|
||
func getMetrics(c *fiber.Ctx) error { | ||
ongoingGames := []Game{} | ||
for gameId, game := range gameManager.GetInstance().StartedGames { | ||
users := make([]string, 0, len(game.Users)) | ||
for k := range game.Users { | ||
users = append(users, k) | ||
} | ||
|
||
ongoingGames = append(ongoingGames, Game{ | ||
Id: gameId, | ||
Status: game.Status, | ||
Users: users, | ||
}) | ||
} | ||
|
||
activeUsers := make([]string, 0, len(gameManager.GetInstance().Users)) | ||
for k := range gameManager.GetInstance().Users { | ||
activeUsers = append(activeUsers, k) | ||
} | ||
|
||
return c.Status(200).JSON(map[string]interface{}{ | ||
"message": "success", | ||
"data": map[string]interface{}{ | ||
"ongoingGames": ongoingGames, | ||
"activeUsers": activeUsers, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package admin | ||
|
||
import ( | ||
"flappy-bird-server/middleware" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func Router(api fiber.Router) { | ||
adminRoute := api.Group("/admin") | ||
|
||
adminRoute.Get("/metric", middleware.CheckAccess, middleware.CheckIsAdmin, getMetrics) | ||
adminRoute.Get("/maintenance", middleware.CheckAccess, middleware.CheckIsAdmin, updateUnderMaintenance) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package admin | ||
|
||
import ( | ||
"flappy-bird-server/lib" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func updateUnderMaintenance(c *fiber.Ctx) error { | ||
lib.UnderMaintenance = !lib.UnderMaintenance | ||
return c.JSON(map[string]interface{}{ | ||
"message": "Maintenance status updated successfully", | ||
"currentStatus": lib.UnderMaintenance, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package auth | ||
|
||
import "net/http" | ||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func Handler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == http.MethodPost { | ||
authenticate(w, r) | ||
return | ||
} | ||
http.Error(w, "method not allowed", 400) | ||
func Router(api fiber.Router) { | ||
authRoute := api.Group("/auth") | ||
|
||
authRoute.Post("/", authenticate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
package gametype | ||
|
||
import ( | ||
"net/http" | ||
"flappy-bird-server/middleware" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func Handler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == http.MethodPost { | ||
addGameType(w, r) | ||
return | ||
} | ||
if r.Method == http.MethodGet { | ||
getGameTypes(w, r) | ||
return | ||
} | ||
http.Error(w, "method not allowed", 400) | ||
func Router(api fiber.Router) { | ||
gameTypeRoute := api.Group("/game-type") | ||
|
||
gameTypeRoute.Post("/", middleware.CheckAccess, addGameType) | ||
gameTypeRoute.Get("/", getGameTypes) | ||
} |
Oops, something went wrong.