response

package
v0.0.0-...-890f6be Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 4 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"}

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

Functions

func AddErrorHandlingMiddleware

func AddErrorHandlingMiddleware() gin.HandlerFunc

AddErrorHandlingMiddleware is used to add error handling middleware.

func EncodeJSON

func EncodeJSON(_ context.Context, w http.ResponseWriter, response interface{}) error

EncodeJSON encode response to json.

Types

type Response

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

Response response struct.

func (*Response) String

func (resp *Response) String() string

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.

func (*Response) WrapError

func (resp *Response) WrapError(err error) *Response

WrapError wrap error to response.

Jump to

Keyboard shortcuts

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