Documentation
¶
Index ¶
- Constants
- func Black(msg string) string
- func Blue(msg string) string
- func Cyan(msg string) string
- func Green(msg string) string
- func Magenta(msg string) string
- func Red(msg string) string
- func SetColor(msg string, conf, bg, text int) string
- func White(msg string) string
- func Yellow(msg string) string
- type Cookie
- type Core
- type Ctx
- func (c *Ctx) Body() string
- func (c *Ctx) ClearCookie(key ...string)
- func (c *Ctx) Cookie(cookie *Cookie)
- func (c *Ctx) Cookies(key ...string) (value string)
- func (c *Ctx) Download(file string, name ...string)
- func (c *Ctx) FormValue(k string) (v string)
- func (c *Ctx) Fresh() bool
- func (c *Ctx) Get(k string) string
- func (c Ctx) Host() string
- func (c *Ctx) IP() string
- func (c *Ctx) IPs() []string
- func (c *Ctx) JSON(data interface{}) error
- func (c *Ctx) JSONP(data interface{}, callback ...string) error
- func (c *Ctx) Next(err ...error)
- func (c *Ctx) Params(k string) (v string)
- func (c *Ctx) Path() string
- func (c *Ctx) Query(k string) (value string)
- func (c *Ctx) ReadBody(out interface{}) error
- func (c *Ctx) Redirect(path string, status ...int)
- func (c *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error
- func (c *Ctx) Send(bodies ...interface{})
- func (c *Ctx) SendFile(file string, noCompression ...bool)
- func (c *Ctx) SendStatus(code int)
- func (c *Ctx) Set(k, v string)
- func (c *Ctx) Vars(k string, v ...interface{}) (val interface{})
- func (c *Ctx) Write(bodies ...interface{})
- type Handler
- type Options
- type Route
Constants ¶
const ( MIMETextXML = "text/xml" MIMETextHTML = "text/html" MIMETextPlain = "text/plain" MIMEApplicationJSON = "application/json" MIMEApplicationJavaScript = "application/javascript" MIMEApplicationXML = "application/xml" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types were copied from labstack/echo
const ( // Authentication HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" // Caching HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" // Client hints HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" // Conditionals HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" // Connection management HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" // Content negotiation HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" // Controls HeaderCookie = "Cookie" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-Cookie" // CORS 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" // Do Not Track HeaderDNT = "DNT" HeaderTk = "Tk" // Downloads HeaderContentDisposition = "Content-Disposition" // Message body information HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" // Proxies HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" // Redirects HeaderLocation = "Location" // Request context HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" // Response context HeaderAllow = "Allow" HeaderServer = "Server" // Range requests HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" // Security HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy" HeaderExpectCT = "Expect-CT" HeaderFeaturePolicy = "Feature-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" // Server-sent event HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" // Transfer coding HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" // WebSockets HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" // Other 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" )
HTTP Headers were copied from net/http.
const ( TextBlack = iota + 30 TextRed TextGreen TextYellow TextBlue TextMagenta TextCyan TextWhite )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cookie ¶
type Cookie struct {
Name string
Value string
Path string
Domain string
Expires time.Time
Secure bool
HTTPOnly bool
SameSite string
}
Cookie struct
type Ctx ¶
type Ctx struct {
*Core
*fasthttp.RequestCtx
*Route
// contains filtered or unexported fields
}
Ctx web context
func (*Ctx) Body ¶
Body contains the raw body submitted in a POST request. If a key is provided, it returns the form value 获得某个值用 c.FormValue
func (*Ctx) ClearCookie ¶
ClearCookie expires a specific cookie by key. If no key is provided it expires all cookies.
func (*Ctx) Download ¶
Download transfers the file from path as an attachment. Typically, browsers will prompt the user for download. By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog). Override this default with the filename parameter.
func (*Ctx) Fresh ¶
Fresh When the response is still “fresh” in the client’s cache true is returned, otherwise false is returned to indicate that the client cache is now stale and the full response should be sent. When a client sends the Cache-Control: no-cache request header to indicate an end-to-end reload request, this module will return false to make handling these requests transparent. https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L33
func (*Ctx) IPs ¶
IPs returns an string slice of IP addresses specified in the X-Forwarded-For request header.
func (*Ctx) SaveFile ¶
func (c *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error
SaveFile saves any multipart file to disk.
func (*Ctx) Send ¶
func (c *Ctx) Send(bodies ...interface{})
Send sets the HTTP response body. The Send body can be of any type.
type Options ¶
type Options struct {
Prefork bool // multiple go processes listening on the some port
// ETag 发送etag
ETag bool
ServerName string
// Fasthttp options
Concurrency int // default: 256 * 1024
NoDefaultDate bool
DisableKeepalive bool
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxRequestBodySize int
Debug bool
}
Options all options