response

package
v0.0.0-...-695ed52 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OK request is successful.
	OK = &Response{
		Code:    http.StatusOK,
		Message: "ok",
		Data:    nil,
	}

	// Err request is failed.
	Err = &Response{
		Code:    http.StatusInternalServerError,
		Message: "unknown error",
		Data:    nil,
	}
)

Functions

func AddErrorHandlingMiddleware

func AddErrorHandlingMiddleware() gin.HandlerFunc

AddErrorHandlingMiddleware is used to add error handling middleware.

Types

type Response

type Response struct {
	Code    int         `json:"code,omitempty"`
	Message string      `json:"msg,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

Response defines the response struct.

func (*Response) WithData

func (resp *Response) WithData(data any) *Response

WithData set response data.

func (*Response) WithMessage

func (resp *Response) WithMessage(message string) *Response

WithMessage set response message.

Jump to

Keyboard shortcuts

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