Documentation
¶
Index ¶
- Constants
- func DecodeRequestIntoStruct(w http.ResponseWriter, r *http.Request, dest interface{}) error
- func GenerateStreamResponse(w http.ResponseWriter, r *http.Response, ctx context.Context, ...) error
- func GetPaginationValues(r *http.Request) (uint32, uint32, error)
- func ParseRequestFilterParams(r *http.Request, f *FilterParamsDTO)
- func ReturnError(w http.ResponseWriter, err error, httpStatus int)
- func ReturnInternalServerError(w http.ResponseWriter, code, message string)
- func ReturnRawError(w http.ResponseWriter, code, message string, status int)
- func ReturnResponseToClient(w http.ResponseWriter, value interface{})
- func ReturnResponseToClientWithStatus(w http.ResponseWriter, value interface{}, httpStatus int)
- func SendResponse(w http.ResponseWriter, statusCode int, success bool, message string, ...)
- type APIResponse
- type ErrorDTO
- type FilterParamsDTO
- type Meta
- type Pagination
Constants ¶
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 GenerateStreamResponse ¶ added in v2.1.0
func GetPaginationValues ¶
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 ¶
NewErrorDTO returns a new ErrorDTO
type FilterParamsDTO ¶
type Meta ¶
type Meta struct {
Timestamp int64 `json:"timestamp"`
RequestID string `json:"requestId,omitempty"`
Pagination *Pagination `json:"pagination,omitempty"`
}
Meta contains additional metadatadata