Documentation
¶
Overview ¶
Package http provides custom HTTP components
Index ¶
Constants ¶
const ( // CodeValidationError represents the error code for validation failures during input processing or validation checks. CodeValidationError = "VALIDATION_ERROR" // MsgValidationError represents the error message for validation failures during input validation checks. MsgValidationError = "validation failed" // CodeInvalidRequest represents the error code for an invalid or improper request made to the system. CodeInvalidRequest = "INVALID_REQUEST" // MsgInvalidRequest represents the error message for an invalid or improperly formed request. MsgInvalidRequest = "invalid request" // CodeInternalError represents the error code for an unspecified internal server error encountered in the system. CodeInternalError = "INTERNAL_ERROR" // MsgInternalError represents the error message returned when the system fails to log in a customer. MsgInternalError = "an unexpected error occurred" // CodeNotFound represents the error code indicating that the requested resource could not be found in the system. CodeNotFound = "NOT_FOUND" // MsgNotFound represents the error message indicating that the requested resource could not be found. MsgNotFound = "resource not found" )
Variables ¶
This section is empty.
Functions ¶
func RequestInfoMiddleware ¶
func RequestInfoMiddleware() gin.HandlerFunc
RequestInfoMiddleware is a middleware that attaches request-specific information to the context.
func ServeTestHTTPRequest ¶
func ServeTestHTTPRequest( t *testing.T, h TestHandler, httpMethod string, route string, token string, queryParams map[string]string, jsonPayload string, ) *httptest.ResponseRecorder
ServeTestHTTPRequest executes a test case for the given handler.
func SetupTestEnv ¶
SetupTestEnv initializes the test environment with default values common to all tests.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Details []string `json:"details"`
}
ErrorResponse represents a standardized structure for API error responses containing code, message, and optional details.
func GetErrorResponseFromValidationErr ¶
func GetErrorResponseFromValidationErr(err error) ErrorResponse
GetErrorResponseFromValidationErr gets the ErrorResponse based on the error type returned from the validation
func NewErrorResponse ¶
func NewErrorResponse(code, message string) ErrorResponse
NewErrorResponse creates and returns a new ErrorResponse with the provided code and message, and an empty details slice.
type HttpResponseBuilder ¶
type HttpResponseBuilder struct {
// contains filtered or unexported fields
}
HttpResponseBuilder is a type used to build and return HTTP response payloads in JSON format.
func NewInternalErrorRespBuilder ¶
func NewInternalErrorRespBuilder() HttpResponseBuilder
NewInternalErrorRespBuilder creates a builder for the INTERNAL_ERROR JSON used in tests.
func NewInvalidRequestRespBuilder ¶
func NewInvalidRequestRespBuilder() HttpResponseBuilder
NewInvalidRequestRespBuilder creates a builder for the INVALID_REQUEST JSON used in tests.
func NewNotFoundRespBuilder ¶
func NewNotFoundRespBuilder() HttpResponseBuilder
NewNotFoundRespBuilder creates a builder for the NOT_FOUND JSON used in tests.
func NewValidationErrorRespBuilder ¶
func NewValidationErrorRespBuilder() HttpResponseBuilder
NewValidationErrorRespBuilder creates a builder for the VALIDATION_ERROR JSON used in tests.
func (HttpResponseBuilder) Build ¶
func (b HttpResponseBuilder) Build() string
Build returns the JSON string.
func (HttpResponseBuilder) WithDetails ¶
func (b HttpResponseBuilder) WithDetails(details ...string) HttpResponseBuilder
WithDetails sets the details of the response.
type TestHandler ¶
TestHandler defines an interface for registering routes within a Gin web engine.