Documentation
¶
Index ¶
- Variables
- func Bind(req *http.Request, obj any, binding binding.Binding) error
- func DefaultBind(req *http.Request, obj any) error
- func IsAjax(req *http.Request) bool
- func IsSSL(req *http.Request) bool
- func IsScript(req *http.Request) bool
- func JSONResponse(w http.ResponseWriter, code int, v any) error
- func JSONResponseWithCode(w http.ResponseWriter, code int, v any) error
- func OKJSONResponse(w http.ResponseWriter, v any) error
- func OKResponse(w http.ResponseWriter)
- func OKXMLResponse(w http.ResponseWriter, v any) error
- func XMLResponse(w http.ResponseWriter, code int, v any) error
- func XMLResponseWithCode(w http.ResponseWriter, code int, v any) error
- type BaseResponse
- type BaseResponseErr
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 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 ResponseContentTypeJSON = "application/json" ResponseContentTypeXML = "application/xml" )
View Source
var (
CompileIsScript = []string{
"curl",
"wget",
"collectd",
"python",
"urllib",
"java",
"jakarta",
"httpclient",
"phpcrawl",
"libwww",
"perl",
"go-http",
"okhttp",
"lua-resty",
"winhttp",
"awesomium",
}
)
Functions ¶
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, code int, v any) error
func JSONResponseWithCode ¶
func JSONResponseWithCode(w http.ResponseWriter, code int, v any) error
JSONResponseWithCode writes v as json string into w with code.
func OKJSONResponse ¶
func OKJSONResponse(w http.ResponseWriter, v any) error
OKJSONResponse writes v into w with http.StatusOK.
func OKXMLResponse ¶
func OKXMLResponse(w http.ResponseWriter, v any) error
OKXMLResponse writes v into w with http.StatusOK.
func XMLResponse ¶
func XMLResponse(w http.ResponseWriter, code int, v any) error
func XMLResponseWithCode ¶
func XMLResponseWithCode(w http.ResponseWriter, code int, v any) error
XMLResponseWithCode writes v as xml string into w with code.
Types ¶
type BaseResponse ¶
type BaseResponse[T any] struct { // Code represents the business code, not the http status code. Code int `json:"code" xml:"code"` // Msg represents the business message, if Code = BusinessCodeOK, // and Msg is empty, then the Msg will be set to BusinessMsgSuccess. Msg string `json:"msg" xml:"msg"` // Data represents the business data. Data T `json:"data,omitempty" xml:"data,omitempty"` }
BaseResponse is the base response struct.
type BaseResponseErr ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.