Documentation
¶
Index ¶
Constants ¶
const (
ErrInvalidFieldValueType = "invalid field value type, expected: '%s'"
)
Variables ¶
var ( ErrCodeNilFailFieldError string ErrCodeNilFailDataError string ErrCodeNilError string ErrCodeNilResponse string )
Functions ¶
This section is empty.
Types ¶
type DefaultResponse ¶ added in v0.9.5
type DefaultResponse struct {
// contains filtered or unexported fields
}
DefaultResponse struct
func NewDebugResponse ¶ added in v0.4.6
func NewDebugResponse( body any, debugBody any, httpStatus int, ) *DefaultResponse
NewDebugResponse creates a new debug response
Parameters:
- body: The response body
- debugBody: The debug response body
- httpStatus: The HTTP status
Returns:
- *DefaultResponse: The default response
func NewResponse ¶ added in v0.3.0
func NewResponse( body any, httpStatus int, ) *DefaultResponse
NewResponse creates a new response
Parameters:
- body: The response body
- httpStatus: The HTTP status
Returns:
- *DefaultResponse: The default response
func (DefaultResponse) Body ¶ added in v0.9.5
func (d DefaultResponse) Body(mode *goflagsmode.Flag) any
Body returns the response body
Parameters:
- mode: The flag mode
Returns:
- any: The response body
func (DefaultResponse) HTTPStatus ¶ added in v0.9.5
func (d DefaultResponse) HTTPStatus() int
HTTPStatus returns the HTTP status
Returns:
- int: The HTTP status
type Encoder ¶ added in v0.11.0
type Encoder interface {
gojsonecoder.Encoder
EncodeResponse(
response Response,
) ([]byte, error)
EncodeAndWriteResponse(
w http.ResponseWriter,
response Response,
) error
}
Encoder interface
type Error ¶ added in v0.12.0
Error struct (would be an error for Error body responses, but to avoid repetition, it's named Error)
func NewDebugError ¶ added in v0.12.0
NewDebugError creates a new JSend error with debug information
Parameters:
- debugErr: The debug error
- err: The error
- httpStatus: The HTTP status code
Returns:
- *Error: The JSend error
func NewDebugErrorWithCode ¶ added in v0.12.0
NewDebugErrorWithCode creates a new JSend error with debug information and error code
Parameters:
- debugErr: The debug error
- err: The error
- errCode: The error code
- httpStatus: The HTTP status code
Returns:
func NewError ¶ added in v0.12.0
NewError creates a new JSend error
Parameters:
- err: The error
- httpStatus: The HTTP status code
Returns:
- *Error: The JSend error
func NewErrorWithCode ¶ added in v0.12.0
NewErrorWithCode creates a new JSend error with error code
Parameters:
- err: The error
- errCode: The error code
- httpStatus: The HTTP status code
Returns:
- *Error: The JSend error
type FailDataError ¶ added in v0.12.0
FailDataError struct
func NewFailDataError ¶ added in v0.12.0
func NewFailDataError( data any, httpStatus int, ) *FailDataError
NewFailDataError creates a new JSend fail data error
Parameters:
- data: The fail data
- httpStatus: The HTTP status
Returns:
- *FailDataError: The JSend fail data error
func NewFailDataErrorWithCode ¶ added in v0.12.0
func NewFailDataErrorWithCode( data any, errorCode string, httpStatus int, ) *FailDataError
NewFailDataErrorWithCode creates a new JSend fail data error with error code
Parameters:
- data: The fail data
- errorCode: The error code
- httpStatus: The HTTP status
Returns:
- *FailDataError: The JSend fail data error
func (FailDataError) Error ¶ added in v0.12.0
func (f FailDataError) Error() string
Error returns the data field as a string from the fail data error
Returns:
- string: The error message
type FailFieldError ¶ added in v0.12.0
FailFieldError struct
func NewFailFieldError ¶ added in v0.12.0
func NewFailFieldError( field string, err error, httpStatus int, ) *FailFieldError
NewFailFieldError creates a new JSend fail field error
Parameters:
- field: The field
- err: The field error
- httpStatus: The HTTP status
Returns:
- *FailFieldError: The JSend fail field error
- string: The error code
func NewFailFieldErrorWithCode ¶ added in v0.12.0
func NewFailFieldErrorWithCode( field string, err error, errorCode string, httpStatus int, ) *FailFieldError
NewFailFieldErrorWithCode creates a new JSend fail field error with error code
Parameters:
- field: The field
- err: The field error
- errorCode: The error code
- httpStatus: The HTTP status
Returns:
- *FailFieldError: The JSend fail field error
func (FailFieldError) Data ¶ added in v0.12.0
func (f FailFieldError) Data() map[string][]string
Data returns a response data map from the fail body error
Returns:
- map[string][]string: The response data map
func (FailFieldError) Error ¶ added in v0.12.0
func (f FailFieldError) Error() string
Error returns the error message from the fail body error
Returns:
- string: The error message
type ProtoJSONEncoder ¶ added in v0.12.3
ProtoJSONEncoder interface