httpx

package module
v0.0.0-...-1c53ea4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-httpx

httpx

Documentation

Index

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 Bind

func Bind(req *http.Request, obj any) error

func BindForm

func BindForm(req *http.Request, obj any) error

func BindHeaders

func BindHeaders(req *http.Request, obj any) error

func BindJSON

func BindJSON(req *http.Request, obj any) error

func BindQuery

func BindQuery(req *http.Request, obj any) error

func BindXML

func BindXML(req *http.Request, obj any) error

func Form

func Form(r *http.Request, postMaxMemory int64) (form map[string][]string, found bool)

func IsAjax

func IsAjax(req *http.Request) bool

func IsConnect

func IsConnect(req *http.Request) bool

func IsDelete

func IsDelete(req *http.Request) bool

func IsGet

func IsGet(req *http.Request) bool

func IsHead

func IsHead(req *http.Request) bool

func IsOptions

func IsOptions(req *http.Request) bool

func IsPatch

func IsPatch(req *http.Request) bool

func IsPost

func IsPost(req *http.Request) bool

func IsPut

func IsPut(req *http.Request) bool

func IsSSL

func IsSSL(req *http.Request) bool

func IsScript

func IsScript(req *http.Request) bool

func IsTrace

func IsTrace(req *http.Request) bool

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 Method

func Method(req *http.Request) string

func NewErrMsg

func NewErrMsg(code int, msg string) error

NewErrMsg creates a new CodeMsg.

func OKJSONBaseResponse

func OKJSONBaseResponse(w http.ResponseWriter, v any) error

OKJSONBaseResponse writes v into w with http.StatusOK.

func OKResponse

func OKResponse(w http.ResponseWriter)

OKResponse writes HTTP 200 OK into w.

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

type BaseResponseErr interface {
	GetCode() int
	error
}

type CodeMsg

type CodeMsg struct {
	Code int
	Msg  string
}

func (*CodeMsg) Error

func (c *CodeMsg) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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