Documentation ¶
Overview ¶
Package http provides a set of functions for working with HTTP requests and responses. It is an extension of the go-zero package https://github.com/zeromicro/go-zero/tree/master/rest/httpx, it provides a base response struct, as before, you can only respond a json string like this:
httpx.OkJson(w, message{Name: "anyone"})
then you can receive a json string like this:
{"name":"anyone"}
but now, you can respond a json string with base response struct like this:
JsonBaseResponse(w, message{Name: "anyone"})
then you can receive a json string like this:
{"code":0,"msg":"ok","data":{"name":"anyone"}}
Index ¶
Constants ¶
View Source
const ( // BusinessCodeOK represents the business code for success. BusinessCodeOK = 0 // BusinessMsgOk represents the business message for success. BusinessMsgOk = "OK" // BusinessCodeError represents the business code for error. BusinessCodeError = -1 BusinessMsgError = "INTERNAL SERVER ERROR" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseResponse ¶
type BaseResponse[T any] struct { // Code represents the business code, not the http status code. Code int `json:"code"` // Msg represents the business message, if Code = BusinessCodeOK, // and Msg is empty, then the Msg will be set to BusinessMsgOk. Msg string `json:"msg"` // Data represents the business data. Data T `json:"data,omitempty"` }
BaseResponse is the base response struct.
Click to show internal directories.
Click to hide internal directories.