qxRes

package
v0.1.38 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

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

func JsonBaseResponse(w http.ResponseWriter, r *http.Request, res any, err any)

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 OkHTML

func OkHTML(w http.ResponseWriter, v string)

OkHTML writes v into w with 200 OK.

func OkHTMLCtx

func OkHTMLCtx(ctx context.Context, w http.ResponseWriter, v string)

OkHTMLCtx writes v into w with 200 OK.

func OkXml

func OkXml(w http.ResponseWriter, v any)

OkXml 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

func WriteHTMLCtx(ctx context.Context, w http.ResponseWriter, code int, v string)

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

func WriteXmlCtx(ctx context.Context, w http.ResponseWriter, code int, v any)

WriteXmlCtx writes v as xml string into w with code.

func XmlBaseResponse

func XmlBaseResponse(w http.ResponseWriter, r *http.Request, res any, err any)

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.

Jump to

Keyboard shortcuts

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