engine

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2017 License: Apache-2.0 Imports: 10 Imported by: 105

Documentation

Overview

Copyright 2012 The Gorilla Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2str

func Bytes2str(b []byte) string

func Clear

func Clear(r Request)

Clear removes all values stored for a given request.

This is usually called by a handler wrapper to clean up request variables at the end of a request lifetime. See ClearHandler().

func Delete

func Delete(r Request, key interface{})

Delete removes a value stored for a given key in a given request.

func Get

func Get(r Request, key interface{}) interface{}

Get returns a value stored for a given key in a given request.

func GetAll

func GetAll(r Request) map[interface{}]interface{}

GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.

func GetAllOk

func GetAllOk(r Request) (map[interface{}]interface{}, bool)

GetAllOk returns all stored values for the request as a map and a boolean value that indicates if the request was registered.

func GetOk

func GetOk(r Request, key interface{}) (interface{}, bool)

GetOk returns stored value and presence state like multi-value return of map access.

func Purge

func Purge(maxAge int) int

Purge removes request data stored for longer than maxAge, in seconds. It returns the amount of requests removed.

If maxAge <= 0, all request data is removed.

This is only used for sanity check: in case context cleaning was not properly set some request data can be kept forever, consuming an increasing amount of memory. In case this is detected, Purge() must be called periodically until the problem is fixed.

func Set

func Set(r Request, key, val interface{})

Set stores a value for a given key in a given request.

func Str2bytes

func Str2bytes(s string) []byte

Types

type Config

type Config struct {
	Address            string       // TCP address to listen on.
	Listener           net.Listener // Custom `net.Listener`. If set, server accepts connections on it.
	TLSConfig          *tls.Config
	TLSCertFile        string        // TLS certificate file path.
	TLSKeyFile         string        // TLS key file path.
	DisableHTTP2       bool          // Disables HTTP/2.
	ReadTimeout        time.Duration // Maximum duration before timing out read of the request.
	WriteTimeout       time.Duration // Maximum duration before timing out write of the response.
	MaxConnsPerIP      int
	MaxRequestsPerConn int
	MaxRequestBodySize int
}

Config defines engine configuration.

type Engine

type Engine interface {
	SetHandler(Handler)
	SetLogger(logger.Logger)
	Start() error
	Stop() error
}

Engine defines an interface for HTTP server.

type Handler

type Handler interface {
	ServeHTTP(Request, Response)
}

Handler defines an interface to server HTTP requests via `ServeHTTP(Request, Response)` function.

func ClearHandler

func ClearHandler(h Handler) Handler

ClearHandler wraps an http.Handler and clears request values at the end of a request lifetime.

type HandlerFunc

type HandlerFunc func(Request, Response)

HandlerFunc is an adapter to allow the use of `func(Request, Response)` as HTTP handlers.

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(req Request, res Response)

ServeHTTP serves HTTP request.

type Header interface {
	// Add adds the key, value pair to the header. It appends to any existing values
	// associated with key.
	Add(string, string)

	// Del deletes the values associated with key.
	Del(string)

	// Get gets the first value associated with the given key. If there are
	// no values associated with the key, Get returns "".
	Get(string) string

	// Set sets the header entries associated with key to the single element value.
	// It replaces any existing values associated with key.
	Set(string, string)

	Object() interface{}

	Std() http.Header
}

Header defines an interface for HTTP header.

type Request

type Request interface {
	// Scheme returns the HTTP protocol scheme, `http` or `https`.
	Scheme() string

	// Host returns HTTP request host. Per RFC 2616, this is either the value of
	// the `Host` header or the host name given in the URL itself.
	Host() string

	// SetHost sets the host of the request.
	SetHost(string)

	// URI returns the unmodified `Request-URI` sent by the client.
	URI() string

	// SetURI sets the URI of the request.
	SetURI(string)

	// URL returns `engine.URL`.
	URL() URL

	// Header returns `engine.Header`.
	Header() Header

	// Proto returns the HTTP proto. (HTTP/1.1 etc.)
	Proto() string

	// RemoteAddress returns the client's network address.
	RemoteAddress() string

	// RealIP returns the client's network address based on `X-Forwarded-For`
	// or `X-Real-IP` request header.
	RealIP() string

	// Method returns the request's HTTP function.
	Method() string

	// SetMethod sets the HTTP method of the request.
	SetMethod(string)

	// Body returns request's body.
	Body() io.ReadCloser

	SetBody(io.Reader)

	// FormValue returns the form field value for the provided name.
	FormValue(string) string
	Object() interface{}

	Form() URLValuer
	PostForm() URLValuer

	// MultipartForm returns the multipart form.
	MultipartForm() *multipart.Form

	// IsTLS returns true if HTTP connection is TLS otherwise false.
	IsTLS() bool
	Cookie(string) string
	Referer() string

	// UserAgent returns the client's `User-Agent`.
	UserAgent() string

	// FormFile returns the multipart form file for the provided name.
	FormFile(string) (multipart.File, *multipart.FileHeader, error)

	// ContentLength returns the size of request's body.
	Size() int64

	BasicAuth() (string, string, bool)

	StdRequest() *http.Request
}

Request defines an interface for HTTP request.

type Response

type Response interface {
	// Header returns `engine.Header`
	Header() Header

	// WriteHeader sends an HTTP response header with status code.
	WriteHeader(int)

	SetKeepBody(bool)

	// Write writes the data to the connection as part of an HTTP reply.
	Write(b []byte) (int, error)

	// Status returns the HTTP response status.
	Status() int

	// Size returns the number of bytes written to HTTP response.
	Size() int64

	// Committed returns true if HTTP response header is written, otherwise false.
	Committed() bool

	// SetWriter sets the HTTP response writer.
	SetWriter(io.Writer)

	// Write returns the HTTP response writer.
	Writer() io.Writer
	Object() interface{}

	Hijack(func(net.Conn))
	Body() []byte
	Redirect(string, int)
	NotFound()
	SetCookie(*http.Cookie)
	ServeFile(string)
	Stream(func(io.Writer) bool)
	Error(string, ...int)

	StdResponseWriter() http.ResponseWriter
}

Response defines an interface for HTTP response.

type URL

type URL interface {
	SetPath(string)
	RawPath() string
	Path() string
	QueryValue(string) string
	QueryValues(string) []string
	Query() url.Values
	RawQuery() string
	SetRawQuery(string)
	String() string
	Object() interface{}
}

URL defines an interface for HTTP request url.

type URLValuer

type URLValuer interface {
	Add(string, string)
	Del(string)
	Get(string) string
	Gets(string) []string
	Set(string, string)
	Encode() string
	All() map[string][]string
	Reset(url.Values)
}

URLValuer Wrap url.Values

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL