Documentation
¶
Index ¶
- Constants
- func NewCookie() httpCookie
- type ErrMiddleware
- type Handler
- type HandlerFunc
- type Middleware
- type Next
- type Request
- func (h *Request) AddCookie(c *http.Cookie)
- func (h *Request) BasicAuth() (username string, password string, ok bool)
- func (h *Request) Clone(ctx context.Context) *http.Request
- func (h *Request) Context() context.Context
- func (h *Request) Cookie(name string) (httpCookie, error)
- func (h *Request) Cookies() []*http.Cookie
- func (h *Request) ErrorMiddleware(e error, code int) Request
- func (h *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (h *Request) FormValue(key string) string
- func (h *Request) MultipartReader() (*multipart.Reader, error)
- func (h *Request) ParseForm() error
- func (h *Request) ParseMultipartForm(maxMemory int64) error
- func (h *Request) ProtoAtLeast(major int, minor int) bool
- func (h *Request) Referer() string
- func (h *Request) UserAgent() string
- func (h *Request) WithContext(ctx context.Context) Request
- func (h *Request) Write(w io.Writer) error
- func (h *Request) WriteProxy(w io.Writer) error
- type Response
- type Router
Constants ¶
View Source
const ( HeaderContentType = "Content-Type" MimeApplicationJson = "application/json" MimeTextHtml = "text/html; charset=UTF-8" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrMiddleware ¶
type HandlerFunc ¶
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Middleware ¶
type Request ¶
type Request struct { Method string URL *url.URL Proto string ProtoMajor int ProtoMinor int Header http.Header Body io.ReadCloser GetBody func() (io.ReadCloser, error) ContentLength int64 TransferEncoding []string Close bool Host string Form url.Values PostForm url.Values MultipartForm *multipart.Form Trailer http.Header RemoteAddr string RequestURI string TLS *tls.ConnectionState Cancel <-chan struct{} Response *http.Response // contains filtered or unexported fields }
func (*Request) ParseMultipartForm ¶
type Response ¶
type Response interface { // Get header Header() http.Header // Write writes the data to the connection as part of an HTTP reply. Write([]byte) (int, error) // WriteHeader sends an HTTP response header with the provided status code. WriteHeader(statusCode int) // Sets the response’s HTTP header field to value Set(string, string) Response // Sets the HTTP status for the response Status(int) Response // Sets the Content-Type HTTP header to the MIME type as determined by the specified type. Type(string) Response // Sends a JSON response. Json(data interface{}) // Sends the HTTP response. Send(data interface{}) // Sets a created cookie. Cookie(httpCookie) Response // Clears the cookie specified by name. ClearCookie(cookie httpCookie) Response // Redirects to the URL derived from the specified path, with specified status. Redirect(path string, code int) // Sets the response Location HTTP header to the specified path parameter. Location(path string) Response // Appends the specified value to the HTTP response header field. Append(key string, val string) Response // Renders a view and sends the rendered HTML string to the client. Render(args ...interface{}) error }
type Router ¶
type Router interface { // Routes HTTP GET requests to the specified path with the specified callback functions. Get(string, Handler, ...Middleware) Router // Routes HTTP CONNECT requests to the specified path with the specified callback functions Connect(string, Handler, ...Middleware) Router // Routes HTTP DELETE requests to the specified path with the specified callback functions Delete(string, Handler, ...Middleware) Router // Routes HTTP HEAD requests to the specified path with the specified callback functions Head(string, Handler, ...Middleware) Router // Routes HTTP PUT requests to the specified path with the specified callback functions Put(string, Handler, ...Middleware) Router // Routes HTTP PATCH requests to the specified path with the specified callback functions Patch(string, Handler, ...Middleware) Router // Routes HTTP TRACE requests to the specified path with the specified callback functions Trace(string, Handler, ...Middleware) Router // Routes HTTP POST requests to the specified path with the specified callback functions Post(string, Handler, ...Middleware) Router // Mounts the specified middleware function Use(Middleware) Router // Sets static files Static(folder string, path ...string) Router // Sets a logger Log(*log.Logger) Router // Sets a context Ctx(context.Context) Router // Binds and listens for connections on the specified host and port. Listen(port int, args ...interface{}) error // ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. ServeHTTP(w http.ResponseWriter, r *http.Request) // Sets a host name Host(string) Router // ParseFiles creates a new Template and parses the template definitions from the named files. Template(path string) Router // SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled. By default, keep-alives are always enabled. // Only very resource-constrained environments or servers in the process of shutting down should disable them. SetKeepAlivesEnabled(v bool) // RegisterOnShutdown registers a function to call on Shutdown. // This can be used to gracefully shutdown connections that have undergone ALPN protocol upgrade or // that have been hijacked. This function should start protocol-specific graceful shutdown, // but should not wait for shutdown to complete. RegisterOnShutdown(f func()) // Close immediately closes all active net.Listeners and any connections in state StateNew, // StateActive, or StateIdle. For a graceful shutdown, use Shutdown. // // Close does not attempt to close (and does not even know about) any hijacked connections, such as WebSockets. // // Close returns any error returned from closing the Server's underlying Listener(s). Close() error // Shutdown gracefully shuts down the server without interrupting any active connections. // Shutdown works by first closing all open listeners, then closing all idle connections, // and then waiting indefinitely for connections to return to idle and then shut down. // If the provided context expires before the shutdown is complete, Shutdown returns the context's error, // otherwise it returns any error returned from closing the Server's underlying Listener(s). // // When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return // ErrServerClosed. Make sure the program doesn't exit and waits instead for Shutdown to return. // // Shutdown does not attempt to close nor wait for hijacked connections such as WebSockets. // The caller of Shutdown should separately notify such long-lived connections of shutdown and // wait for them to close, if desired. See RegisterOnShutdown for a way to register shutdown notification functions. // // Once Shutdown has been called on a server, it may not be reused; future calls to methods // such as Serve will return ErrServerClosed. Shutdown(ctx context.Context) }
Click to show internal directories.
Click to hide internal directories.