rest

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PARAM_OFFSET           string = "offset"
	PARAM_MAX_ROWS         string = "limit"
	QUERY_PARAM_START_DATE string = "startDate"
	QUERY_PARAM_END_DATE   string = "endDate"
)

Variables

This section is empty.

Functions

func DecodeRequestIntoStruct

func DecodeRequestIntoStruct(w http.ResponseWriter, r *http.Request, dest interface{}) error

func GetPaginationValues

func GetPaginationValues(r *http.Request) (uint32, uint32, error)

GetPaginationValues extracts pagination parameters from the request URL. It parses 'offset' and 'maxRows' query parameters into uint32 values. Returns the parsed values and an error if any of the parameters are invalid.

func ParseRequestFilterParams

func ParseRequestFilterParams(r *http.Request, f *FilterParamsDTO)

parseRequestFilterParams parses the request filter parameters and fills the FilterParamsDTO struct. The function logs any errors found in the parameters and fills the struct with default values. If the FilterParamsDTO parameter is nil, a new one is created.

func ReturnError

func ReturnError(w http.ResponseWriter, err error, httpStatus int)

func ReturnInternalServerError

func ReturnInternalServerError(w http.ResponseWriter, code, message string)

func ReturnRawError

func ReturnRawError(w http.ResponseWriter, code, message string, status int)

Returns a Raw error writting the code and the message received

func ReturnResponseToClient

func ReturnResponseToClient(w http.ResponseWriter, value interface{})

func ReturnResponseToClientWithStatus

func ReturnResponseToClientWithStatus(w http.ResponseWriter, value interface{}, httpStatus int)

func SendResponse

func SendResponse(w http.ResponseWriter, statusCode int, success bool, message string, data interface{}, errors interface{}, pagination *Pagination)

SendResponse envía una respuesta JSON con la estructura común

Types

type APIResponse

type APIResponse struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Errors  interface{} `json:"errors,omitempty"`
	Meta    Meta        `json:"meta"`
}

APIResponse es la estructura común para todas las respuestas

type ErrorDTO

type ErrorDTO struct {
	Code      string    `json:"code"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
}

func NewErrorDTO

func NewErrorDTO(code, message string) ErrorDTO

NewErrorDTO returns a new ErrorDTO

type FilterParamsDTO

type FilterParamsDTO struct {
	StartDate int64
	EndDate   int64
	Offset    uint32
	MaxRows   uint32
}

type Meta

type Meta struct {
	Timestamp  int64       `json:"timestamp"`
	RequestID  string      `json:"requestId,omitempty"`
	Pagination *Pagination `json:"pagination,omitempty"`
}

Meta contains additional metadatadata

type Pagination

type Pagination struct {
	Page       uint32 `json:"page"`
	PageSize   uint32 `json:"pageSize"`
	TotalPages uint32 `json:"totalPages"`
	TotalItems uint32 `json:"totalItems"`
}

Pagination contains pagination information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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