Context (Ctx)
Ctx is a thin wrapper around *fiber.Ctx that adds request parsing, typed response helpers, user access, and i18n support. It embeds *fiber.Ctx, so all standard Fiber methods are available.
type Ctx struct { *fiber.Ctx}Request Parsing
Section titled “Request Parsing”ParseBody(dst any) error
Section titled “ParseBody(dst any) error”Decodes the JSON request body into dst and validates it using struct tags.
type CreateUserDTO struct { Name string `json:"name" validate:"required"` Email string `json:"email" validate:"required,email"`}
func (c *UserController) create(ctx *core.Ctx) error { var dto CreateUserDTO if err := ctx.ParseBody(&dto); err != nil { return err // 400 if malformed JSON, 422 if validation fails } // dto is safe to use return ctx.Created(dto)}Returns:
400 Bad Request— malformed JSON422 Unprocessable Entity— validation failed (with[]FieldErrorbody)
ParsePagination() PageQuery
Section titled “ParsePagination() PageQuery”Parses ?page and ?limit query parameters from the request.
q := ctx.ParsePagination()// q.Page — default: 1// q.Limit — default: 20, max: 100See Pagination for full reference.
Response Helpers
Section titled “Response Helpers”All helpers JSON-encode the body and set the appropriate Content-Type header.
OK(data any) error
Section titled “OK(data any) error”Responds with 200 OK.
return ctx.OK(user)return ctx.OK(map[string]string{"message": "success"})Created(data any) error
Section titled “Created(data any) error”Responds with 201 Created.
return ctx.Created(newUser)NoContent() error
Section titled “NoContent() error”Responds with 204 No Content (no body).
return ctx.NoContent()NotFound(message ...string) error
Section titled “NotFound(message ...string) error”Responds with 404 Not Found. Accepts an optional custom message.
return ctx.NotFound()return ctx.NotFound("user not found")User Access
Section titled “User Access”SetUser(user any)
Section titled “SetUser(user any)”Stores the authenticated user in the request context. Called from guard middleware.
ctx.SetUser(&AuthUser{ID: "123", Role: "admin"})User() any
Section titled “User() any”Returns the raw user value stored by SetUser.
raw := ctx.User()UserAs[T any](c *Ctx) (T, bool)
Section titled “UserAs[T any](c *Ctx) (T, bool)”Generic helper to extract the user as a specific type.
user, ok := core.UserAs[*AuthUser](ctx)if !ok { return core.Unauthorized("not authenticated")}Returns (zero, false) if the user was not set or the type assertion fails.
Internationalization
Section titled “Internationalization”Lang() string
Section titled “Lang() string”Extracts the preferred locale from the Accept-Language header. Returns "en" if the header is absent or empty.
locale := ctx.Lang() // e.g. "es", "pt-BR", "en"T(key string, args ...any) string
Section titled “T(key string, args ...any) string”Translates a key using the configured Translator. Falls back to the key itself if no translator is set or the key is not found.
msg := ctx.T("errors.user_not_found")msg := ctx.T("welcome.message", username)The translator is set on the app with app.SetTranslator(t). See Interfaces — Translator.
Fiber Methods
Section titled “Fiber Methods”Since Ctx embeds *fiber.Ctx, all Fiber request methods are available:
ctx.Params("id") // URL parameterctx.Query("search") // query string valuectx.Get("Authorization") // request headerctx.IP() // client IPctx.Method() // HTTP methodctx.Path() // request pathctx.Context() // underlying context.Context (for service calls)ctx.Locals("key", value) // read/write per-request valuesSee the Fiber documentation for the full list.