webutil

package
v0.0.0-...-6528de2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Response

func Response(c *fiber.Ctx, code int, message string, data any) error

Response is a takes in context object, an HTTP status code, a message string and some data.

func StatusBadRequest

func StatusBadRequest(c *fiber.Ctx, data any) error

StatusBadRequest is ...

func StatusInternalServerError

func StatusInternalServerError(c *fiber.Ctx) error

StatusInternalServerError is ...

func StatusNotFound

func StatusNotFound(c *fiber.Ctx) error

StatusNotFound is ...

func StatusOK

func StatusOK(c *fiber.Ctx, message string, data any) error

StatusOK is ...

func StatusUnauthorized

func StatusUnauthorized(c *fiber.Ctx, data any) error

StatusUnauthorized is ...

Types

type HTTPResponse

type HTTPResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

HTTPResponse represents response body of API

type PaginationQuery

type PaginationQuery struct {
	Limit  int32  `json:"limit" form:"limit"`
	Offset int32  `json:"offset" form:"offset"`
	SortBy string `json:"sort_by" form:"sort_by"` // Corrected typo in form tag.
}

PaginationQuery represents pagination parameters.

func GetPaginationFromCtx

func GetPaginationFromCtx(c *fiber.Ctx) *PaginationQuery

GetPaginationFromCtx creates a PaginationQuery from the fiber context.

func (*PaginationQuery) GetQueryString

func (p *PaginationQuery) GetQueryString() string

GetQueryString constructs a query string with the pagination parameters.

func (*PaginationQuery) GetSelectPage

func (p *PaginationQuery) GetSelectPage() int32

GetSelectPage calculates the current page based on offset and limit.

func (*PaginationQuery) GetTotalPages

func (p *PaginationQuery) GetTotalPages(totalRecords int32) int32

GetTotalPages calculates the total number of pages based on total records.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL