engine

package
v2.2.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 18 Imported by: 104

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderSetCookie = `Set-Cookie`
)

Functions

func AddressPort added in v1.3.9

func AddressPort(address string) int

func Bytes2str

func Bytes2str(b []byte) string

func Get

func Get(name string) func(*Config) Engine

func NewListener added in v1.3.0

func NewListener(address string, reuse bool) (net.Listener, error)

func Register added in v1.6.0

func Register(name string, newEngine func(*Config) Engine)

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.
	ReusePort          bool
	TLSAuto            bool
	TLSHosts           []string
	TLSEmail           string
	TLSCacheDir        string
	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.

func (*Config) AddTLSCert added in v1.3.0

func (c *Config) AddTLSCert(certFile, keyFile string) *Config

func (*Config) InitListener added in v1.3.0

func (c *Config) InitListener(before ...func() error) error

func (*Config) InitTLSConfig added in v1.3.0

func (c *Config) InitTLSConfig(certAndKey ...string) *Config

func (*Config) InitTLSListener added in v1.3.0

func (c *Config) InitTLSListener(before ...func() error) error

func (*Config) NewAutoTLSManager added in v1.4.3

func (c *Config) NewAutoTLSManager(hosts ...string) *autocert.Manager

func (*Config) Print added in v1.3.0

func (c *Config) Print(engine string)

func (*Config) SetListener added in v1.3.0

func (c *Config) SetListener(ln net.Listener) *Config

func (*Config) SupportAutoTLS added in v1.3.0

func (c *Config) SupportAutoTLS(autoTLSManager *autocert.Manager, hosts ...string) *Config

type Engine

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

Engine defines an interface for HTTP server.

func New added in v1.6.0

func New(name string, config *Config) Engine

type Handler

type Handler interface {
	ServeHTTP(Request, Response)
}

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

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)

	// Size 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)

	KeepBody(bool)

	// Write writes the data to the connection as part of an HTTP reply.
	Write([]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)
	Merge(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