jsend

package
v0.14.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDebugErrorResponse

func NewDebugErrorResponse(
	message string,
	debugMessage string,
	httpStatus int,
) gonethttpresponse.Response

NewDebugErrorResponse creates a new JSend error response with debug information

Parameters:

  • message: The error message
  • debugMessage: The debug message
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewDebugErrorResponseWithCode

func NewDebugErrorResponseWithCode(
	message string,
	debugMessage string,
	code string,
	httpStatus int,
) gonethttpresponse.Response

NewDebugErrorResponseWithCode creates a new JSend error response with debug information and error code

Parameters:

  • message: The error message
  • debugMessage: The debug message
  • code: The error code
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewErrorResponse

func NewErrorResponse(
	message string,
	httpStatus int,
) gonethttpresponse.Response

NewErrorResponse creates a new JSend error response

Parameters:

  • message: The error message
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewErrorResponseWithCode

func NewErrorResponseWithCode(
	message string,
	code string,
	httpStatus int,
) gonethttpresponse.Response

NewErrorResponseWithCode creates a new JSend error response with error code

Parameters:

  • message: The error message
  • code: The error code
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewFailResponse

func NewFailResponse(
	data any,
	httpStatus int,
) gonethttpresponse.Response

NewFailResponse creates a new JSend fail response

Parameters:

  • data: The data
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewFailResponseWithCode

func NewFailResponseWithCode(
	data any,
	code string,
	httpStatus int,
) gonethttpresponse.Response

NewFailResponseWithCode creates a new JSend fail response with error code

Parameters:

  • data: The data
  • code: The error code
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

func NewResponseFromError

func NewResponseFromError(err *gonethttpresponse.Error) gonethttpresponse.Response

NewResponseFromError creates a new JSend response from an error

Parameters:

  • err: The error to convert to a response

Returns:

  • Response: The response

func NewResponseFromFailDataError

func NewResponseFromFailDataError(failDataErr *gonethttpresponse.FailDataError) gonethttpresponse.Response

NewResponseFromFailDataError creates a new JSend response from a fail data error

Parameters:

  • failDataErr: The fail data error to convert to a response

Returns:

  • Response: The response

func NewResponseFromFailFieldError

func NewResponseFromFailFieldError(failErr *gonethttpresponse.FailFieldError) gonethttpresponse.Response

NewResponseFromFailFieldError creates a new JSend response from a fail error

Parameters:

  • failErr: The fail error to convert to a response

Returns:

  • Response: The response

func NewSuccessResponse

func NewSuccessResponse(
	data any,
	httpStatus int,
) gonethttpresponse.Response

NewSuccessResponse creates a new JSend success response

Parameters:

  • data: The data
  • httpStatus: The HTTP status code

Returns:

  • Response: The response

Types

type ErrorBody

type ErrorBody struct {
	Status  Status `json:"status"`
	Message string `json:"message,omitempty"`
	Code    string `json:"code,omitempty"`
}

ErrorBody struct

func NewErrorBody

func NewErrorBody(
	message string,
) *ErrorBody

NewErrorBody creates a new JSend error response body

Parameters:

  • message: The error message

Returns:

  • *ErrorBody: The JSend error body

func NewErrorBodyWithCode

func NewErrorBodyWithCode(
	message string,
	code string,
) *ErrorBody

NewErrorBodyWithCode creates a new JSend error response body with error code

Parameters:

  • message: The error message
  • code: The error code

Returns:

  • *ErrorBody: The JSend error body

type FailBody

type FailBody struct {
	Status Status `json:"status"`
	Code   string `json:"code,omitempty"`
	Data   any    `json:"data,omitempty"`
}

FailBody struct

func NewFailBody

func NewFailBody(
	data any,
) *FailBody

NewFailBody creates a new JSend fail response body

Parameters:

  • data: The data

Returns:

func NewFailBodyWithCode

func NewFailBodyWithCode(
	data any,
	code string,
) *FailBody

NewFailBodyWithCode creates a new JSend fail response body with error code

Parameters:

  • data: The data
  • code: The error code

Returns:

  • *FailBody: The JSend fail body

type Status

type Status string

Status is the response body status

const (
	// StatusSuccess indicates a successful response
	StatusSuccess Status = "success"

	// StatusFail indicates a failed response due to client error
	StatusFail Status = "fail"

	// StatusError indicates an error response due to server error
	StatusError Status = "error"
)

type SuccessBody

type SuccessBody[T any] struct {
	Status Status `json:"status"`
	Data   T      `json:"data,omitempty"`
}

SuccessBody struct

func NewSuccessBody

func NewSuccessBody[T any](
	data T,
) *SuccessBody[T]

NewSuccessBody creates a new JSend success response body

Parameters:

  • data: The data

Returns:

  • *SuccessBody: The JSend success body

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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