Skip to content

Commit 5a866b0

Browse files
committed
test new migrations
1 parent 2f5a50f commit 5a866b0

File tree

20 files changed

+86
-46
lines changed

20 files changed

+86
-46
lines changed

clean-code/app/server/handlers/books.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// GetBooks returns a handler function that retrieves all books.
1313
func GetBooks(service services.BooksService) fiber.Handler {
1414
return func(c fiber.Ctx) error {
15-
books, err := service.GetBooks(c.RequestCtx())
15+
books, err := service.GetBooks(c.Context())
1616
if err != nil {
1717
slog.Error("GetBooks failed", "error", err)
1818
return sendError(c, fiber.StatusInternalServerError, "internal error")
@@ -34,7 +34,7 @@ func AddBook(service services.BooksService) fiber.Handler {
3434
}
3535
// For production use add proper validation here.
3636

37-
err := service.SaveBook(c.RequestCtx(), book)
37+
err := service.SaveBook(c.Context(), book)
3838
if err != nil {
3939
slog.Error("AddBook failed", "error", err)
4040
return sendError(c, fiber.StatusInternalServerError, "internal error")

csrf-with-session/main.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"os"
1313
"time"
1414

15+
"github.com/gofiber/fiber/v3/extractors"
16+
1517
"github.com/gofiber/fiber/v3"
1618
"github.com/gofiber/fiber/v3/middleware/csrf"
1719
"github.com/gofiber/fiber/v3/middleware/session"
@@ -86,8 +88,8 @@ func main() {
8688

8789
// Initialize a session store
8890
sessConfig := session.Config{
89-
IdleTimeout: 30 * time.Minute, // Expire sessions after 30 minutes of inactivity
90-
Extractor: session.FromCookie("__Host-session"), // Recommended to use the __Host- prefix when serving the app over TLS
91+
IdleTimeout: 30 * time.Minute, // Expire sessions after 30 minutes of inactivity
92+
Extractor: extractors.FromCookie("__Host-session"), // Recommended to use the __Host- prefix when serving the app over TLS
9193
CookieSecure: true,
9294
CookieHTTPOnly: true,
9395
CookieSameSite: "Lax",
@@ -123,11 +125,11 @@ func main() {
123125
// Configure the CSRF middleware
124126
csrfConfig := csrf.Config{
125127
Session: store,
126-
Extractor: csrf.FromForm("csrf"), // In this example, we will be using a hidden input field to store the CSRF token
127-
CookieName: "__Host-csrf", // Recommended to use the __Host- prefix when serving the app over TLS
128-
CookieSameSite: "Lax", // Recommended to set this to Lax or Strict
129-
CookieSecure: true, // Recommended to set to true when serving the app over TLS
130-
CookieHTTPOnly: true, // Recommended, otherwise if using JS framework recomend: false and Extractor: csrf.FromHeader("X-CSRF-Token")
128+
Extractor: extractors.FromForm("csrf"), // In this example, we will be using a hidden input field to store the CSRF token
129+
CookieName: "__Host-csrf", // Recommended to use the __Host- prefix when serving the app over TLS
130+
CookieSameSite: "Lax", // Recommended to set this to Lax or Strict
131+
CookieSecure: true, // Recommended to set to true when serving the app over TLS
132+
CookieHTTPOnly: true, // Recommended, otherwise if using JS framework recomend: false and KeyLookup: "header:X-CSRF-Token"
131133
ErrorHandler: csrfErrorHandler,
132134
IdleTimeout: 30 * time.Minute,
133135
}

csrf/routes/mainServer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66
"time"
77

8+
"github.com/gofiber/fiber/v3/extractors"
9+
810
"github.com/gofiber/fiber/v3"
911
"github.com/gofiber/fiber/v3/middleware/csrf"
1012
"github.com/gofiber/fiber/v3/middleware/recover"
@@ -45,7 +47,7 @@ var csrfProtection = csrf.New(csrf.Config{
4547
Next: func(c fiber.Ctx) bool {
4648
return csrfActivated
4749
},
48-
Extractor: csrf.FromForm("_csrf"),
50+
Extractor: extractors.FromForm("_csrf"),
4951
CookieName: "csrf_",
5052
CookieSameSite: "Strict",
5153
IdleTimeout: 1 * time.Hour,

docker-mariadb-clean-arch/internal/city/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (h *CityHandler) getCity(c fiber.Ctx) error {
6363
defer cancel()
6464

6565
// Fetch parameter.
66-
targetedCityID, err := fiber.Params[int](c, "cityID"), nil
66+
targetedCityID, err := fiber.Params[int](c, "cityID"), error(nil)
6767
if err != nil {
6868
return c.Status(fiber.StatusBadRequest).JSON(&fiber.Map{
6969
"status": "fail",

docker-mariadb-clean-arch/internal/city/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (h *CityHandler) checkIfCityExistsMiddleware(c fiber.Ctx) error {
1313
defer cancel()
1414

1515
// Fetch parameter.
16-
targetedCityID, err := fiber.Params[int](c, "cityID"), nil
16+
targetedCityID, err := fiber.Params[int](c, "cityID"), error(nil)
1717
if err != nil {
1818
return c.Status(fiber.StatusBadRequest).JSON(&fiber.Map{
1919
"status": "fail",

docker-mariadb-clean-arch/internal/user/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (h *UserHandler) getUser(c fiber.Ctx) error {
5757
defer cancel()
5858

5959
// Fetch parameter.
60-
targetedUserID, err := fiber.Params[int](c, "userID"), nil
60+
targetedUserID, err := fiber.Params[int](c, "userID"), error(nil)
6161
if err != nil {
6262
return c.Status(fiber.StatusBadRequest).JSON(&fiber.Map{
6363
"status": "fail",

docker-mariadb-clean-arch/internal/user/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (h *UserHandler) checkIfUserExistsMiddleware(c fiber.Ctx) error {
1313
defer cancel()
1414

1515
// Fetch parameter.
16-
targetedUserID, err := fiber.Params[int](c, "userID"), nil
16+
targetedUserID, err := fiber.Params[int](c, "userID"), error(nil)
1717
if err != nil {
1818
return c.Status(fiber.StatusBadRequest).JSON(&fiber.Map{
1919
"status": "fail",

ent-mysql/routes/routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
var ctx = context.Background()
1313

1414
func GetBook(c fiber.Ctx) error {
15-
id, _ := fiber.Params[int](c, "id"), nil
15+
id, _ := fiber.Params[int](c, "id"), error(nil)
1616
b, err := database.DBConn.Book.
1717
Get(ctx, id)
1818
if b == nil {
@@ -54,7 +54,7 @@ func CreateBook(c fiber.Ctx) error {
5454
}
5555

5656
func DeleteBook(c fiber.Ctx) error {
57-
id, _ := fiber.Params[int](c, "id"), nil
57+
id, _ := fiber.Params[int](c, "id"), error(nil)
5858
err := database.DBConn.Book.
5959
DeleteOneID(id).
6060
Exec(ctx)
@@ -68,7 +68,7 @@ func DeleteBook(c fiber.Ctx) error {
6868
func UpdateBook(c fiber.Ctx) error {
6969
title := c.Query("title")
7070
author := c.Query("author")
71-
id, _ := fiber.Params[int](c, "id"), nil
71+
id, _ := fiber.Params[int](c, "id"), error(nil)
7272
if title == "" || author == "" {
7373
return c.Status(fiber.StatusBadRequest).JSON("Not enough data for updating")
7474
}

entgo-sveltekit/handler/todo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewTodoHandler(client *entity.Client) *TodoHandler {
2222
//
2323
// [GET] /todos
2424
func (th *TodoHandler) GetAllTodos(c fiber.Ctx) error {
25-
todos, err := th.Client.Todo.Query().All(c.RequestCtx())
25+
todos, err := th.Client.Todo.Query().All(c.Context())
2626
if err != nil {
2727
return fiber.NewError(fiber.StatusConflict, "Failed to retrieve todos")
2828
}
@@ -38,7 +38,7 @@ func (th *TodoHandler) GetTodoByID(c fiber.Ctx) error {
3838
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "Invalid ID"})
3939
}
4040

41-
todo, err := th.Client.Todo.Get(c.RequestCtx(), id)
41+
todo, err := th.Client.Todo.Get(c.Context(), id)
4242
if err != nil {
4343
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"message": "Todo item not found"})
4444
}
@@ -64,7 +64,7 @@ func (th *TodoHandler) CreateTodo(c fiber.Ctx) error {
6464
SetID(todo.ID).
6565
SetContent(todo.Content).
6666
SetCompleted(todo.Completed).
67-
Save(c.RequestCtx())
67+
Save(c.Context())
6868
if err != nil {
6969
return fiber.NewError(fiber.StatusConflict, "Failed to create todo")
7070
}
@@ -85,14 +85,14 @@ func (th *TodoHandler) UpdateTodoByID(c fiber.Ctx) error {
8585
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "Invalid request body"})
8686
}
8787

88-
todo, err := th.Client.Todo.Get(c.RequestCtx(), id)
88+
todo, err := th.Client.Todo.Get(c.Context(), id)
8989
if err != nil {
9090
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"message": "Todo item not found"})
9191
}
9292
updatedTodo, err := todo.Update().
9393
SetContent(data.Content).
9494
SetCompleted(data.Completed).
95-
Save(c.RequestCtx())
95+
Save(c.Context())
9696
if err != nil {
9797
return fiber.NewError(fiber.StatusConflict, "Failed to update todo")
9898
}
@@ -108,7 +108,7 @@ func (th *TodoHandler) DeleteTodoByID(c fiber.Ctx) error {
108108
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "Invalid ID"})
109109
}
110110

111-
err = th.Client.Todo.DeleteOneID(id).Exec(c.RequestCtx())
111+
err = th.Client.Todo.DeleteOneID(id).Exec(c.Context())
112112
if err != nil {
113113
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"message": "Todo item not found"})
114114
}

entgo-sveltekit/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ func main() {
6060

6161
// Serve static files
6262
app.All("/*", static.New("", static.Config{
63-
FS: os.DirFS(template.Dist()),
64-
NotFoundFile: "index.html",
65-
IndexNames: []string{"index.html"},
63+
FS: os.DirFS(template.Dist()),
64+
// TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated
65+
// NotFoundFile: "index.html",
66+
IndexNames: []string{"index.html"},
6667
}))
6768

6869
// Start the server

0 commit comments

Comments
 (0)