response

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotFound

func NotFound(ctx *gin.Context)

func RedirectToLogin

func RedirectToLogin(ctx *gin.Context, dst string)

SendNotFound directly sends a not found response

func Send

func Send(ctx *gin.Context, statusCode int, data interface{})

Send provides a shortcut to send a (potentially) successful response

func SendError

func SendError(ctx *gin.Context, statusCode int, data interface{})

SendError provides a shortcut to send an unsuccessful response

func SendErrorWithParams

func SendErrorWithParams(ctx *gin.Context, statusCode int, data interface{}, errorParams map[string]string)

SendErrorWithParams the same as above but for errors that require error parameters

func SendFile

func SendFile(c *gin.Context, storageDomain model.StorageDomain, path string)

SendFile sends file to client with caching header

func SendInternalServerError

func SendInternalServerError(ctx *gin.Context)

SendInternalServerError directly sends an internal server error response

Types

type Response

type Response struct {
	// Response payload
	// Ok if the response was successful or not
	Ok bool `json:"ok"`

	// Message the payload of the response, depending on the endpoint/response status
	Message any `json:"message"`

	// ErrorParams parameters defined if the response is not successful to help client's debugging
	ErrorParams map[string]string `json:"error_params,omitempty"`
	// contains filtered or unexported fields
}

func New

func New(ok bool, statusCode int, data interface{}) *Response

New provides a shortcut to a successful response object

func NewResponse

func NewResponse(ok bool, message any, errorParams map[string]string, statusCode int) *Response

func (*Response) GetMessage added in v1.6.3

func (m *Response) GetMessage() any

func (*Response) IsError

func (m *Response) IsError() bool

func (*Response) Send

func (m *Response) Send(c *gin.Context)

Jump to

Keyboard shortcuts

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