Documentation ¶
Index ¶
- Constants
- Variables
- func Bind(req *http.Request, obj any) error
- func BindForm(req *http.Request, obj any) error
- func BindHeaders(req *http.Request, obj any) error
- func BindJSON(req *http.Request, obj any) error
- func BindQuery(req *http.Request, obj any) error
- func BindXML(req *http.Request, obj any) error
- func Form(r *http.Request, postMaxMemory int64) (form map[string][]string, found bool)
- func IsAjax(req *http.Request) bool
- func IsConnect(req *http.Request) bool
- func IsDelete(req *http.Request) bool
- func IsGet(req *http.Request) bool
- func IsHead(req *http.Request) bool
- func IsOptions(req *http.Request) bool
- func IsPatch(req *http.Request) bool
- func IsPost(req *http.Request) bool
- func IsPut(req *http.Request) bool
- func IsSSL(req *http.Request) bool
- func IsScript(req *http.Request) bool
- func IsTrace(req *http.Request) bool
- func JSONBaseResponse(w http.ResponseWriter, code int, v any) error
- func JSONResponseWithCode(w http.ResponseWriter, code int, v any) error
- func Method(req *http.Request) string
- func NewErrMsg(code int, msg string) error
- func OKJSONBaseResponse(w http.ResponseWriter, v any) error
- func OKResponse(w http.ResponseWriter)
- func OKXMLBaseResponse(w http.ResponseWriter, v any) error
- func XMLBaseResponse(w http.ResponseWriter, code int, v any) error
- func XMLResponseWithCode(w http.ResponseWriter, code int, v any) error
- type BaseResponse
- type BaseResponseErr
- type CodeMsg
Constants ¶
View Source
const ( CharsetUTF8 = "charset=UTF-8" ContentTypeJSON = "application/json" ContentTypeJSONCharsetUTF8 = ContentTypeJSON + "; " + CharsetUTF8 ContentTypeJavaScript = "application/javascript" ContentTypeJavaScriptCharsetUTF8 = ContentTypeJavaScript + "; " + CharsetUTF8 ContentTypeXML = "application/xml" ContentTypeXMLCharsetUTF8 = ContentTypeXML + "; " + CharsetUTF8 ContentTypeTextXML = "text/xml" ContentTypeTextXMLCharsetUTF8 = ContentTypeTextXML + "; " + CharsetUTF8 ContentTypeForm = "application/x-www-form-urlencoded" ContentTypeProtobuf = "application/protobuf" ContentTypeMsgpack = "application/msgpack" ContentTypeTextHTML = "text/html" ContentTypeTextHTMLCharsetUTF8 = ContentTypeTextHTML + "; " + CharsetUTF8 ContentTypeTextPlain = "text/plain" ContentTypeTextPlainCharsetUTF8 = ContentTypeTextPlain + "; " + CharsetUTF8 ContentTypeMultipartForm = "multipart/form-data" ContentTypeOctetStream = "application/octet-stream" )
View Source
const ( SchemeHttp = "http" SchemeHttps = "https" )
View Source
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderRetryAfter = "Retry-After" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-Ip" HeaderXRequestID = "X-Request-Id" HeaderXCorrelationID = "X-Correlation-Id" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderCacheControl = "Cache-Control" HeaderConnection = "Connection" HeaderUserAgent = "User-Agent" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" HeaderReferrerPolicy = "Referrer-Policy" )
Headers
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 )
View Source
var (
RegRequestIsScript = "curl|wget|collectd|python|urllib|java|jakarta|httpclient|phpcrawl|libwww|perl|go-http|okhttp|lua-resty|winhttp|awesomium"
)
Functions ¶
func JSONBaseResponse ¶
func JSONBaseResponse(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 OKJSONBaseResponse ¶
func OKJSONBaseResponse(w http.ResponseWriter, v any) error
OKJSONBaseResponse writes v into w with http.StatusOK.
func OKXMLBaseResponse ¶
func OKXMLBaseResponse(w http.ResponseWriter, v any) error
OKXMLBaseResponse writes v into w with http.StatusOK.
func XMLBaseResponse ¶
func XMLBaseResponse(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 ¶
Click to show internal directories.
Click to hide internal directories.