Documentation ¶
Index ¶
- Constants
- func Compress(next http.Handler) http.Handler
- func Context(next http.Handler) http.Handler
- func Cors(next http.Handler) http.Handler
- func Error403(w http.ResponseWriter, r *http.Request)
- func Headers(next http.Handler) http.Handler
- func Logging(next http.Handler) http.Handler
- func ProfilerRoutes(r *mux.Router)
- func Recover(next http.Handler) http.Handler
- func Routes(r *mux.Router)
- type AuthMiddleware
- type CompressResponseWriter
- type Response
Constants ¶
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" 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" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" // Access control 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" // 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" )
Variables ¶
This section is empty.
Functions ¶
func ProfilerRoutes ¶
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
示例代码 - 开始 Define our struct
func (*AuthMiddleware) Middleware ¶
func (m *AuthMiddleware) Middleware(next http.Handler) http.Handler
Middleware function, which will be called for each request
type CompressResponseWriter ¶
type CompressResponseWriter struct { io.Writer http.ResponseWriter http.Hijacker http.Flusher http.CloseNotifier }
func (*CompressResponseWriter) Flush ¶
func (w *CompressResponseWriter) Flush()
func (*CompressResponseWriter) Header ¶
func (w *CompressResponseWriter) Header() http.Header
func (*CompressResponseWriter) Hijack ¶
func (w *CompressResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*CompressResponseWriter) Write ¶
func (w *CompressResponseWriter) Write(b []byte) (int, error)
func (*CompressResponseWriter) WriteHeader ¶
func (w *CompressResponseWriter) WriteHeader(code int)
type Response ¶
type Response struct { Writer http.ResponseWriter Status int Size int64 Committed bool // contains filtered or unexported fields }
Response wraps an http.ResponseWriter and implements its interface to be used by an HTTP handler to construct an HTTP response. See: https://golang.org/pkg/net/http/#ResponseWriter
func NewResponse ¶
func NewResponse(w http.ResponseWriter) (r *Response)
NewResponse creates a new instance of Response.
func (*Response) After ¶
func (r *Response) After(fn func())
After registers a function which is called just after the response is written. If the `Content-Length` is unknown, none of the after function is executed.
func (*Response) Before ¶
func (r *Response) Before(fn func())
Before registers a function which is called just before the response is written.
func (*Response) Flush ¶
func (r *Response) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Response) Header ¶
Header returns the header map for the writer that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example) To suppress implicit response headers, set their value to nil. Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
func (*Response) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.