response

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Success success response
	Success = &Response{Code: 2000, Message: "success"}
	// PermissionDenied permission denied response
	PermissionDenied = &Response{Code: 4003, Message: "permission denied"}
	// NotFound not found response
	NotFound = &Response{Code: 4004, Message: "not found"}
	// ManyRequest many request response
	ManyRequest = &Response{Code: 4429, Message: "too many requests"}
	// Failed failed response
	Failed = &Response{Code: 5000, Message: "failed"}
	// AuthFail auth fail response
	AuthFail = &Response{Code: 4001, Message: "auth failed"}
)

Functions

func SetTranslator

func SetTranslator(t *i18n.Bundle)

SetTranslator set translation object

func Translator

func Translator(ctx *gin.Context) *i18n.Printer

Translator The language accepted by users can be obtained by analyzing AcceptLanguages

Types

type Response

type Response struct {
	Code    int         `json:"code"`    // the status code is the status code agreed with the front end and app, not the HTTP status code
	Data    interface{} `json:"data"`    // return data
	Message string      `json:"message"` // customize the returned message content
	// contains filtered or unexported fields
}

Response HTTP return the data structure. You can use this or customize it

func NewResponse

func NewResponse(code int, data interface{}, message ...string) *Response

NewResponse response

code custom status code agreed by server, client and Web
data specific return data
message can not be transmitted, custom message

func (*Response) End

func (rsp *Response) End(c *gin.Context, httpStatus ...int)

End after calling this method, you still need return

func (*Response) JSON

func (rsp *Response) JSON(data interface{}) *Response

JSON set Data, will return json

func (*Response) Msg

func (rsp *Response) Msg(msg string) *Response

Msg msg description

func (*Response) MsgData

func (rsp *Response) MsgData(data interface{}) *Response

MsgData data used for message parsing

func (*Response) Object

func (rsp *Response) Object(_ *gin.Context) *Response

Object get the object directly

Jump to

Keyboard shortcuts

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