Documentation
¶
Index ¶
- Constants
- func JsonBaseResponse(w http.ResponseWriter, r *http.Request, res any, err any)
- func JsonBaseResponseCtx(ctx context.Context, w http.ResponseWriter, r *http.Request, res any, err any)
- func OkHTML(w http.ResponseWriter, v string)
- func OkHTMLCtx(ctx context.Context, w http.ResponseWriter, v string)
- func OkXml(w http.ResponseWriter, v any)
- func OkXmlCtx(ctx context.Context, w http.ResponseWriter, v any)
- func WriteHTML(w http.ResponseWriter, code int, v string)
- func WriteHTMLCtx(ctx context.Context, w http.ResponseWriter, code int, v string)
- func WriteXml(w http.ResponseWriter, code int, v any)
- func WriteXmlCtx(ctx context.Context, w http.ResponseWriter, code int, v any)
- func XmlBaseResponse(w http.ResponseWriter, r *http.Request, res any, err any)
- func XmlBaseResponseCtx(ctx context.Context, w http.ResponseWriter, r *http.Request, res any, err any)
- type BaseResponse
Constants ¶
View Source
const ( SuccessCodeOK = 2000 SuccessMsgOk = "ok" FailedCodeError = -1 XmlContentType = "application/xml" HTMLContentType = "application/html" ContentType = "Content-Type" ContentTypeHtml = "text/html" ContentTypeJson = "application/json" )
Variables ¶
This section is empty.
Functions ¶
func JsonBaseResponse ¶
JsonBaseResponse writes v into w with http.StatusOK.
func JsonBaseResponseCtx ¶
func JsonBaseResponseCtx(ctx context.Context, w http.ResponseWriter, r *http.Request, res any, err any)
JsonBaseResponseCtx writes v into w with http.StatusOK.
func OkHTMLCtx ¶
func OkHTMLCtx(ctx context.Context, w http.ResponseWriter, v string)
OkHTMLCtx writes v into w with 200 OK.
func OkXmlCtx ¶
func OkXmlCtx(ctx context.Context, w http.ResponseWriter, v any)
OkXmlCtx writes v into w with 200 OK.
func WriteHTML ¶
func WriteHTML(w http.ResponseWriter, code int, v string)
WriteHTML writes v as HTML string into w with code.
func WriteHTMLCtx ¶
WriteHTMLCtx writes v as HTML string into w with code.
func WriteXml ¶
func WriteXml(w http.ResponseWriter, code int, v any)
WriteXml writes v as xml string into w with code.
func WriteXmlCtx ¶
WriteXmlCtx writes v as xml string into w with code.
func XmlBaseResponse ¶
XmlBaseResponse writes v into w with http.StatusOK.
func XmlBaseResponseCtx ¶
func XmlBaseResponseCtx(ctx context.Context, w http.ResponseWriter, r *http.Request, res any, err any)
XmlBaseResponseCtx writes v into w with http.StatusOK.
Types ¶
type BaseResponse ¶
type BaseResponse[T any] struct { // Code represents the business code, not the http status code. Code int32 `json:"code" xml:"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" xml:"msg"` // Code represents the business code, not the http status code. Path string `json:"path" xml:"path"` // Msg represents the business message, if Code = BusinessCodeOK, // and Msg is empty, then the Msg will be set to BusinessMsgOk. RequestId string `json:"request_id" xml:"request_id"` // Data represents the business data. Data T `json:"data,omitempty" xml:"data,omitempty"` }
BaseResponse is the base response struct.
Click to show internal directories.
Click to hide internal directories.