Documentation
¶
Index ¶
- Constants
- Variables
- func Blob(w http.ResponseWriter, code int, contentType string, b []byte) error
- func Decode(r *http.Request, v interface{}) error
- func DecodeForm(r io.Reader, v interface{}) error
- func DecodeJSON(r io.Reader, v interface{}) error
- func DecodeXML(r io.Reader, v interface{}) error
- func GetCookie(r *http.Request, cookieName string) (*http.Cookie, error)
- func HandleError(w http.ResponseWriter, resp Error)
- func IsWebSocket(r *http.Request) bool
- func JSON(w http.ResponseWriter, code int, data interface{}) error
- func JSONBlob(w http.ResponseWriter, code int, data []byte) error
- func NoContent(w http.ResponseWriter, code int) error
- func OffsetLimit(r *http.Request) (offset, limit int64)
- func QueryParam(r *http.Request, key string) string
- func RealIP(r *http.Request) string
- func Redirect(w http.ResponseWriter, code int, url string) error
- func RemoveCookie(w http.ResponseWriter, cookieName string, v CookieConfig)
- func RewriteRequestURLTarget(req *http.Request, target *url.URL)
- func Scheme(r *http.Request) string
- func SetCookie(w http.ResponseWriter, value string, cookieName string, v CookieConfig)
- func SetCookieB64(w http.ResponseWriter, body []byte, cookieName string, v CookieConfig) string
- type ContentType
- type CookieConfig
- type Error
- type Response
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" // HeaderAllow is the name of the "Allow" header field used to list the set of methods // advertised as supported by the target resource. Returning an Allow header is mandatory // for status 405 (method not found) and useful for the OPTIONS method in responses. // See RFC 7231: https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1 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" // Access control 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" // Security 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 from echo framework
View Source
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
Variables ¶
View Source
var ErrInvalidRedirectCode = errors.New("invalid redirect code")
Functions ¶
func Decode ¶
Decode detects the correct decoder for use on an HTTP request and marshals into a given interface.
func DecodeForm ¶
DecodeForm decodes a given reader into an interface using the form decoder.
func DecodeJSON ¶
DecodeJSON decodes a given reader into an interface using the json decoder.
func HandleError ¶
func HandleError(w http.ResponseWriter, resp Error)
func IsWebSocket ¶
func OffsetLimit ¶
func RemoveCookie ¶
func RemoveCookie(w http.ResponseWriter, cookieName string, v CookieConfig)
func SetCookie ¶
func SetCookie(w http.ResponseWriter, value string, cookieName string, v CookieConfig)
func SetCookieB64 ¶
func SetCookieB64(w http.ResponseWriter, body []byte, cookieName string, v CookieConfig) string
Types ¶
type ContentType ¶
type ContentType int
ContentType is an enumeration of common HTTP content types.
const ( ContentTypeUnknown ContentType = iota ContentTypePlainText ContentTypeHTML ContentTypeJSON ContentTypeXML ContentTypeForm ContentTypeEventStream )
ContentTypes handled by this package.
func GetRequestContentType ¶
func GetRequestContentType(r *http.Request) ContentType
type CookieConfig ¶
type CookieConfig struct { // Domain for defines the host to which the cookie will be sent. Domain string `cfg:"domain"` // Path that must exist in the requested URL for the browser to send the Cookie header. Path string `cfg:"path"` // MaxAge the number of seconds until the cookie expires. MaxAge int `cfg:"max_age"` // Secure to cookie only sent over HTTPS. Secure bool `cfg:"secure"` // SameSite for Lax 2, Strict 3, None 4. SameSite http.SameSite `cfg:"same_site"` // HttpOnly for true for not accessible by JavaScript. HttpOnly bool `cfg:"http_only"` }
type Error ¶
type Error struct { Msg string `json:"message,omitempty"` Err error `json:"error,omitempty"` Code int `json:"-"` }
func NewErrorAs ¶
func (Error) MarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.