webutil

package
v0.0.0-...-784c0f6 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 7 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 a Fiber context object, an HTTP status code, a message string and some data.

func StatusBadRequest

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

StatusBadRequest is ... 400 error

func StatusInternalServerError

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

StatusInternalServerError is ... 500 error

func StatusNotFound

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

StatusNotFound is ... 404 error

func StatusOK

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

StatusOK is ... 200 ok

func StatusUnauthorized

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

StatusUnauthorized is ... 401 error

Types

type HTTPResponse

type HTTPResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Result  any    `json:"result,omitempty"`
}

HTTPResponse represents response body of API

type MetaInfo

type MetaInfo struct {
	Request Request `json:"request"`
	Data    any     `json:"data"`
}

MetaInfo is ...

func GetRequestInfo

func GetRequestInfo(c *fiber.Ctx, data any) *MetaInfo

GetRequestInfo is ...

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.

type Request

type Request struct {
	UserAgent   string `json:"user_agent"`
	UserIP      string `json:"user_ip"`
	UserCountry string `json:"user_country"`
}

Request is ...

Jump to

Keyboard shortcuts

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