Skip to content

Commit

Permalink
feat: Add Memory module
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatsnake committed Feb 11, 2023
1 parent 839b724 commit b7cf96d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
routes.CountriesRouter(app)
routes.CampRouter(app)
routes.KuromasuRouter(app)
routes.MemoryRouter(app)

log.Fatal(app.Listen(":" + port))
}
28 changes: 28 additions & 0 deletions internal/handlers/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package handlers

import (
"github.com/cheatsnake/shadify/internal/helpers"
"github.com/cheatsnake/shadify/pkg/memory"
"github.com/gofiber/fiber/v2"
)

const (
memoryHeight int = 4
memoryWidth int = 6
memoryPairSize int = 3
memoryShowPositions bool = true
)

func MemoryGenerator(c *fiber.Ctx) error {
width := helpers.GetQueryInt(c, "width", memoryWidth)
height := helpers.GetQueryInt(c, "height", memoryHeight)
pairSize := helpers.GetQueryInt(c, "pair-size", memoryPairSize)
showPositions := helpers.GetQueryBool(c, "show-positions", memoryShowPositions)

result, err := memory.Generate(width, height, pairSize, showPositions)
if err != nil {
return helpers.ThrowError(c, fiber.StatusBadRequest, err.Error())
}

return c.JSON(result)
}
12 changes: 12 additions & 0 deletions internal/routes/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package routes

import (
"github.com/cheatsnake/shadify/internal/handlers"
"github.com/gofiber/fiber/v2"
)

func MemoryRouter(app fiber.Router) {
prefix := "/api/memory"

app.Get(prefix+"/generator", handlers.MemoryGenerator)
}

0 comments on commit b7cf96d

Please sign in to comment.