response

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Response

type Response[T any] struct {
	ErrorDetails perrors.Err `json:"errorDetails"`
	Error        bool        `json:"error"`
	Message      string      `json:"message"`
	Data         T           `json:"data"`
	Status       int         `json:"status"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse[T any](ctx context.Context, msg string, data T) *Response[T]

func (*Response[T]) WithError

func (r *Response[T]) WithError(err error) *Response[T]

WithError sets the error field for the response

func (*Response[T]) WithStatus

func (r *Response[T]) WithStatus(code int) *Response[T]

WithStatus will set the HTTP response status code.

This is not a preferred way of setting status code.

  • Try to use perrors.Err embedded with a status code whenever possible.
  • Default is http.StatusOK and it need not be set explicitly.

func (*Response[T]) Write

func (r *Response[T]) Write(ctx *fasthttp.RequestCtx)

Write will set the `content-type` to `application/json` and write the response to the fasthttp context.

Jump to

Keyboard shortcuts

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