response

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalidFieldValueType = "invalid field value type, expected: '%s'"
)

Variables

View Source
var (
	ErrCodeNilFailFieldError string
	ErrCodeNilFailDataError  string
	ErrCodeNilError          string
	ErrCodeNilResponse       string
)
View Source
var (
	ErrNilResponse       = errors.New("response cannot be nil")
	ErrNilFailFieldError = errors.New("fail field error cannot be nil")
	ErrNilFailDataError  = errors.New("fail data error cannot be nil")
	ErrNilError          = errors.New("error cannot be nil")
)

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

type Error struct {
	DebugErr   error
	Err        error
	ErrorCode  string
	HTTPStatus int
}

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

func NewDebugError(
	debugErr error,
	err error,
	httpStatus int,
) *Error

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

func NewDebugErrorWithCode(
	debugErr error,
	err error,
	errCode string,
	httpStatus int,
) *Error

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

func NewError(
	err error,
	httpStatus int,
) *Error

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

func NewErrorWithCode(
	err error,
	errCode string,
	httpStatus int,
) *Error

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

func (Error) Error added in v0.12.0

func (e Error) Error() string

Error returns the error message from the error

Returns:

  • string: The error message

type FailDataError added in v0.12.0

type FailDataError struct {
	Data       any
	ErrorCode  string
	HTTPStatus int
}

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

type FailFieldError struct {
	Field      string
	Err        error
	ErrorCode  string
	HTTPStatus int
}

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

type ProtoJSONEncoder interface {
	PrecomputeMarshal(
		body any,
	) (map[string]any, error)
}

ProtoJSONEncoder interface

type Response added in v0.3.0

type Response interface {
	Body(mode *goflagsmode.Flag) any
	HTTPStatus() int
}

Response is the interface for the responses

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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