Documentation ¶
Index ¶
- Constants
- Variables
- type Bind
- func (b *Bind) Body(out any) error
- func (b *Bind) Cookie(out any) error
- func (b *Bind) Form(out any) error
- func (b *Bind) Header(out any) error
- func (b *Bind) JSON(out any) error
- func (b *Bind) MultipartForm(out any, size ...int64) error
- func (b *Bind) Query(out any) error
- func (b *Bind) Release()
- func (b *Bind) URI(out any) error
- func (b *Bind) XML(out any) error
- type M
- type Render
- func (r *Render) ContentType(v string)
- func (r *Render) Cookie(cookie *http.Cookie)
- func (r *Render) Data(v []byte)
- func (r *Render) Download(filepath, filename string)
- func (r *Render) EventStream(v any)
- func (r *Render) File(filepath string)
- func (r *Render) Flush()
- func (r *Render) HTML(v string)
- func (r *Render) Header(key, value string)
- func (r *Render) Hijack() (http.Hijacker, bool)
- func (r *Render) JSON(v any)
- func (r *Render) JSONP(callback string, v any)
- func (r *Render) NoContent()
- func (r *Render) PlainText(v string)
- func (r *Render) Redirect(url string)
- func (r *Render) RedirectPermanent(url string)
- func (r *Render) Release()
- func (r *Render) SSEvent(event renderer.SSEvent)
- func (r *Render) Status(status int)
- func (r *Render) Stream(step func(w io.Writer) bool) bool
- func (r *Render) WithoutCookie(name string)
- func (r *Render) XML(v any)
Constants ¶
const ( MIMETextXML = "text/xml" MIMETextHTML = "text/html" MIMETextPlain = "text/plain" MIMETextJavaScript = "text/javascript" MIMETextCSS = "text/css" MIMEEventStream = "text/event-stream" MIMEApplicationXML = "application/xml" MIMEApplicationJSON = "application/json" // Deprecated: use MIMETextJavaScript instead MIMEApplicationJavaScript = "application/javascript" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEOctetStream = "application/octet-stream" MIMEMultipartForm = "multipart/form-data" MIMETextXMLCharsetUTF8 = "text/xml; charset=utf-8" MIMETextHTMLCharsetUTF8 = "text/html; charset=utf-8" MIMETextPlainCharsetUTF8 = "text/plain; charset=utf-8" MIMETextJavaScriptCharsetUTF8 = "text/javascript; charset=utf-8" MIMETextCSSCharsetUTF8 = "text/css; charset=utf-8" MIMEEventStreamCharsetUTF8 = "text/event-stream; charset=utf-8" MIMEApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" // Deprecated: use MIMETextJavaScriptCharsetUTF8 instead MIMEApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" )
MIME types that are commonly used
const ( HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderCookie = "Cookie" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-Cookie" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderOrigin = "Origin" HeaderTimingAllowOrigin = "Timing-Allow-Origin" HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies" HeaderDNT = "DNT" HeaderTk = "Tk" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderLocation = "Location" HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" HeaderAllow = "Allow" HeaderServer = "Server" HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy" HeaderExpectCT = "Expect-CT" HeaderPermissionsPolicy = "Permissions-Policy" HeaderPublicKeyPins = "Public-Key-Pins" HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXDownloadOptions = "X-Download-Options" HeaderXFrameOptions = "X-Frame-Options" HeaderXPoweredBy = "X-Powered-By" HeaderXXSSProtection = "X-XSS-Protection" HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" HeaderAcceptPatch = "Accept-Patch" HeaderAcceptPushPolicy = "Accept-Push-Policy" HeaderAcceptSignature = "Accept-Signature" HeaderAltSvc = "Alt-Svc" HeaderDate = "Date" HeaderIndex = "Index" HeaderLargeAllocation = "Large-Allocation" HeaderLink = "Link" HeaderPushPolicy = "Push-Policy" HeaderRetryAfter = "Retry-After" HeaderServerTiming = "Server-Timing" HeaderSignature = "Signature" HeaderSignedHeaders = "Signed-Headers" HeaderSourceMap = "SourceMap" HeaderUpgrade = "Upgrade" HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control" HeaderXPingback = "X-Pingback" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderXRobotsTag = "X-Robots-Tag" HeaderXUACompatible = "X-UA-Compatible" HeaderAccessControlAllowPrivateNetwork = "Access-Control-Allow-Private-Network" HeaderAccessControlRequestPrivateNetwork = "Access-Control-Request-Private-Network" )
HTTP Headers were copied from net/http.
const ( CookieSameSiteDisabled = "disabled" // not in RFC, just control "SameSite" attribute will not be set. CookieSameSiteLaxMode = "lax" CookieSameSiteStrictMode = "strict" CookieSameSiteNoneMode = "none" )
Cookie SameSite https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
const ( ConstraintInt = "int" ConstraintBool = "bool" ConstraintFloat = "float" ConstraintAlpha = "alpha" ConstraintGUID = "guid" ConstraintMinLen = "minLen" ConstraintMaxLen = "maxLen" ConstraintLen = "len" ConstraintBetweenLen = "betweenLen" ConstraintMinLenLower = "minlen" ConstraintMaxLenLower = "maxlen" ConstraintBetweenLenLower = "betweenlen" ConstraintMin = "min" ConstraintMax = "max" ConstraintRange = "range" ConstraintDatetime = "datetime" ConstraintRegex = "regex" )
Route Constraints
Variables ¶
var ( JSONEncoder = json.NewEncoder JSONDecoder = json.NewDecoder XMLEncoder = xml.NewEncoder XMLDecoder = xml.NewDecoder )
JSON/XML Encoders and Decoders
Functions ¶
This section is empty.
Types ¶
type Bind ¶
type Bind struct {
// contains filtered or unexported fields
}
Bind struct
func (*Bind) Body ¶
Body binds the request body into the struct, map[string]string and map[string][]string. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data If none of the content types above are matched, it'll take a look custom binders by checking the MIMETypes() method of custom binder. If there're no custom binder for mşme type of body, it will return a ErrUnprocessableEntity error.
func (*Bind) Cookie ¶
Cookie binds the requesr cookie strings into the struct, map[string]string and map[string][]string. NOTE: If your cookie is like key=val1,val2; they'll be binded as an slice if your map is map[string][]string. Else, it'll use last element of cookie.
func (*Bind) Header ¶
Header binds the request header strings into the struct, map[string]string and map[string][]string.
func (*Bind) MultipartForm ¶
MultipartForm binds the multipart form into the struct, map[string]string and map[string][]string. Parameter size is the maximum memory in bytes used to parse the form, default is 32MB.
func (*Bind) Query ¶
Query binds the query string into the struct, map[string]string and map[string][]string.
func (*Bind) Release ¶ added in v1.1.3
func (b *Bind) Release()
Release releases the Bind instance back into the pool.
type Render ¶
type Render struct {
// contains filtered or unexported fields
}
Render struct
func NewRender ¶
func NewRender(w http.ResponseWriter, r ...*http.Request) *Render
NewRender creates a new NewRender instance.
func (*Render) ContentType ¶ added in v1.1.2
ContentType sets the Content-Type header for an HTTP response.
func (*Render) Data ¶
Data writes raw bytes to the response, setting the Content-Type as application/octet-stream if not set.
func (*Render) Download ¶
Download sends a file to the response and prompting it to be downloaded by setting the Content-Disposition header.
func (*Render) EventStream ¶
EventStream writes a stream of JSON objects from a channel to the response and setting the Content-Type as text/event-stream if not set.
func (*Render) HTML ¶
HTML writes a string to the response, setting the Content-Type as text/html if not set.
func (*Render) JSON ¶
JSON marshals 'v' to JSON, automatically escaping HTML and setting the Content-Type as application/json if not set.
func (*Render) JSONP ¶
JSONP marshals 'v' to JSON, automatically escaping HTML and setting the Content-Type as application/javascript if not set.
func (*Render) NoContent ¶
func (r *Render) NoContent()
NoContent returns a HTTP 204 "No Content" response.
func (*Render) PlainText ¶
PlainText writes a string to the response, setting the Content-Type as text/plain if not set.
func (*Render) Redirect ¶
Redirect replies to the request with a redirect to url, which may be a path relative to the request path.
func (*Render) RedirectPermanent ¶ added in v1.1.2
RedirectPermanent replies to the request with a redirect to url, which may be a path relative to the request path.
func (*Render) Release ¶ added in v1.1.3
func (r *Render) Release()
Release puts the Render instance back into the pool.
func (*Render) SSEvent ¶ added in v1.1.0
SSEvent writes a Server-Sent Event to the response and setting the Content-Type as text/event-stream if not set.
func (*Render) Stream ¶ added in v1.1.0
Stream sends a streaming response and returns a boolean indicates "Is client disconnected in middle of stream"
func (*Render) WithoutCookie ¶
WithoutCookie deletes a cookie in the response.