Documentation
¶
Index ¶
- Variables
- func DefaultErrorHandler(err error, req *Request, res *Response)
- func DefaultMethodNotAllowedHandler(req *Request, res *Response) error
- func DefaultNotFoundHandler(req *Request, res *Response) error
- type Air
- func (a *Air) BATCH(methods []string, path string, h Handler, gases ...Gas)
- func (a *Air) CONNECT(path string, h Handler, gases ...Gas)
- func (a *Air) Close() error
- func (a *Air) DELETE(path string, h Handler, gases ...Gas)
- func (a *Air) FILE(path, filename string, gases ...Gas)
- func (a *Air) FILES(prefix, root string, gases ...Gas)
- func (a *Air) GET(path string, h Handler, gases ...Gas)
- func (a *Air) Group(prefix string, gases ...Gas) *Group
- func (a *Air) HEAD(path string, h Handler, gases ...Gas)
- func (a *Air) OPTIONS(path string, h Handler, gases ...Gas)
- func (a *Air) PATCH(path string, h Handler, gases ...Gas)
- func (a *Air) POST(path string, h Handler, gases ...Gas)
- func (a *Air) PUT(path string, h Handler, gases ...Gas)
- func (a *Air) Serve() error
- func (a *Air) Shutdown(timeout time.Duration) error
- func (a *Air) TRACE(path string, h Handler, gases ...Gas)
- type Gas
- type Group
- func (g *Group) BATCH(methods []string, path string, h Handler, gases ...Gas)
- func (g *Group) CONNECT(path string, h Handler, gases ...Gas)
- func (g *Group) DELETE(path string, h Handler, gases ...Gas)
- func (g *Group) FILE(path, file string, gases ...Gas)
- func (g *Group) FILES(prefix, root string, gases ...Gas)
- func (g *Group) GET(path string, h Handler, gases ...Gas)
- func (g *Group) Group(prefix string, gases ...Gas) *Group
- func (g *Group) HEAD(path string, h Handler, gases ...Gas)
- func (g *Group) OPTIONS(path string, h Handler, gases ...Gas)
- func (g *Group) PATCH(path string, h Handler, gases ...Gas)
- func (g *Group) POST(path string, h Handler, gases ...Gas)
- func (g *Group) PUT(path string, h Handler, gases ...Gas)
- func (g *Group) TRACE(path string, h Handler, gases ...Gas)
- type Handler
- type Request
- func (r *Request) Bind(v interface{}) error
- func (r *Request) ClientAddress() string
- func (r *Request) Cookie(name string) *http.Cookie
- func (r *Request) Cookies() []*http.Cookie
- func (r *Request) HTTPRequest() *http.Request
- func (r *Request) LocalizedString(key string) string
- func (r *Request) Param(name string) *RequestParam
- func (r *Request) Params() []*RequestParam
- func (r *Request) RemoteAddress() string
- func (r *Request) SetHTTPRequest(hr *http.Request)
- type RequestParam
- type RequestParamValue
- func (rpv *RequestParamValue) Bool() (bool, error)
- func (rpv *RequestParamValue) File() (*multipart.FileHeader, error)
- func (rpv *RequestParamValue) Float32() (float32, error)
- func (rpv *RequestParamValue) Float64() (float64, error)
- func (rpv *RequestParamValue) Int() (int, error)
- func (rpv *RequestParamValue) Int8() (int8, error)
- func (rpv *RequestParamValue) Int16() (int16, error)
- func (rpv *RequestParamValue) Int32() (int32, error)
- func (rpv *RequestParamValue) Int64() (int64, error)
- func (rpv *RequestParamValue) String() string
- func (rpv *RequestParamValue) Uint() (uint, error)
- func (rpv *RequestParamValue) Uint8() (uint8, error)
- func (rpv *RequestParamValue) Uint16() (uint16, error)
- func (rpv *RequestParamValue) Uint32() (uint32, error)
- func (rpv *RequestParamValue) Uint64() (uint64, error)
- type Response
- func (r *Response) Defer(f func())
- func (r *Response) HTTPResponseWriter() http.ResponseWriter
- func (r *Response) ProxyPass(target string) error
- func (r *Response) Push(target string, pos *http.PushOptions) error
- func (r *Response) Redirect(url string) error
- func (r *Response) Render(m map[string]interface{}, templates ...string) error
- func (r *Response) SetCookie(c *http.Cookie)
- func (r *Response) SetHTTPResponseWriter(hrw http.ResponseWriter)
- func (r *Response) WebSocket() (*WebSocket, error)
- func (r *Response) Write(content io.ReadSeeker) error
- func (r *Response) WriteFile(filename string) error
- func (r *Response) WriteHTML(h string) error
- func (r *Response) WriteJSON(v interface{}) error
- func (r *Response) WriteMsgpack(v interface{}) error
- func (r *Response) WriteProtobuf(v interface{}) error
- func (r *Response) WriteString(s string) error
- func (r *Response) WriteTOML(v interface{}) error
- func (r *Response) WriteXML(v interface{}) error
- func (r *Response) WriteYAML(v interface{}) error
- type WebSocket
- func (ws *WebSocket) Close() error
- func (ws *WebSocket) Listen()
- func (ws *WebSocket) WriteBinary(b []byte) error
- func (ws *WebSocket) WriteConnectionClose(status int, reason string) error
- func (ws *WebSocket) WritePing(appData string) error
- func (ws *WebSocket) WritePong(appData string) error
- func (ws *WebSocket) WriteText(text string) error
Constants ¶
This section is empty.
Variables ¶
var Default = New()
Default is the default instance of the `Air`.
Functions ¶
func DefaultErrorHandler ¶
DefaultErrorHandler is the default centralized error handler for the server.
func DefaultMethodNotAllowedHandler ¶
DefaultMethodNotAllowedHandler is the default `Handler` that returns method not allowed error.
func DefaultNotFoundHandler ¶
DefaultNotFoundHandler is the default `Handler` that returns not found error.
Types ¶
type Air ¶
type Air struct {
// AppName is the name of the current web application.
//
// The default value is "air".
AppName string `mapstructure:"app_name"`
// MaintainerEmail is the e-mail address of the one who is responsible
// for maintaining the current web application.
//
// The default value is "".
MaintainerEmail string `mapstructure:"maintainer_email"`
// DebugMode indicates whether the current web application is in debug
// mode.
//
// ATTENTION: Some features will be affected in debug mode.
//
// The default value is false.
DebugMode bool `mapstructure:"debug_mode"`
// Address is the TCP address that the server listens on.
//
// The default value is ":8080".
Address string `mapstructure:"address"`
// HostWhitelist is the hosts allowed by the server.
//
// It only works when the `DebugMode` is false.
//
// The default value is nil.
HostWhitelist []string `mapstructure:"host_whitelist"`
// ReadTimeout is the maximum duration the server reads the request.
//
// The default value is 0.
ReadTimeout time.Duration `mapstructure:"read_timeout"`
// ReadHeaderTimeout is the amount of time allowed the server reads the
// request headers.
//
// The default value is 0.
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
// WriteTimeout is the maximum duration the server writes an response.
//
// The default value is 0.
WriteTimeout time.Duration `mapstructure:"write_timeout"`
// IdleTimeout is the maximum amount of time the server waits for the
// next request. If it is zero, the value of `ReadTimeout` is used. If
// both are zero, the value `ReadHeaderTimeout` is used.
//
// The default value is 0.
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
// MaxHeaderBytes is the maximum number of bytes the server will read
// parsing the request header's names and values, including the request
// line.
//
// The default value is 1048576.
MaxHeaderBytes int `mapstructure:"max_header_bytes"`
// TLSCertFile is the path to the TLS certificate file used when
// starting the server.
//
// The default value is "".
TLSCertFile string `mapstructure:"tls_cert_file"`
// TLSKeyFile is the path to the TLS key file used when starting the
// server.
//
// The default value is "".
TLSKeyFile string `mapstructure:"tls_key_file"`
// ACMEEnabled indicates whether the ACME is enabled.
//
// It only works when the `DebugMode` is false and both of the
// `TLSCertFile` and the `TLSKeyFile` are empty.
//
// The default value is false.
ACMEEnabled bool `mapstructure:"acme_enabled"`
// ACMECertRoot is the root of the ACME certificates.
//
// The default value is "acme-certs".
ACMECertRoot string `mapstructure:"acme_cert_root"`
// HTTPSEnforced indicates whether the HTTPS is enforced.
//
// It only works when the port of the `Address` is neither "80" nor
// "http".
//
// The default value is false.
HTTPSEnforced bool `mapstructure:"https_enforced"`
// WebSocketHandshakeTimeout is the maximum amount of time the server
// waits for the WebSocket handshake to complete.
//
// The default value is 0.
WebSocketHandshakeTimeout time.Duration `mapstructure:"websocket_handshake_timeout"`
// WebSocketSubprotocols is the supported WebSocket subprotocols of the
// server.
//
// The default value is nil.
WebSocketSubprotocols []string `mapstructure:"websocket_subprotocols"`
// NotFoundHandler is a `Handler` that returns not found error.
//
// The default value is the `DefaultNotFoundHandler`.
NotFoundHandler func(*Request, *Response) error `mapstructure:"-"`
// MethodNotAllowedHandler is a `Handler` that returns method not
// allowed error.
//
// The default value is the `DefaultMethodNotAllowedHandler`.
MethodNotAllowedHandler func(*Request, *Response) error `mapstructure:"-"`
// ErrorHandler is the centralized error handler of the server.
//
// The default value is the `DefaultErrorHandler`.
ErrorHandler func(error, *Request, *Response) `mapstructure:"-"`
// ErrorLogger is the `log.Logger` that logs errors that occur in the
// server.
//
// If nil, logging is done via the log package's standard logger.
//
// The default value is nil.
ErrorLogger *log.Logger `mapstructure:"-"`
// Pregases is the `Gas` chain stack that performs before routing.
//
// The default value is nil.
Pregases []Gas `mapstructure:"-"`
// Gases is the `Gas` chain stack that performs after routing.
//
// The default value is nil.
Gases []Gas `mapstructure:"-"`
// AutoPushEnabled indicates whether the auto push is enabled.
//
// The default value is false.
AutoPushEnabled bool `mapstructure:"auto_push_enabled"`
// MinifierEnabled indicates whether the minifier is enabled.
//
// The default value is false.
MinifierEnabled bool `mapstructure:"minifier_enabled"`
// MinifierMIMETypes is the MIME types that will be minified.
// Unsupported MIME types will be silently ignored.
//
// The default value is ["text/html", "text/css",
// "application/javascript", "application/json", "application/xml",
// "image/svg+xml"].
MinifierMIMETypes []string `mapstructure:"minifier_mime_types"`
// GzipEnabled indicates whether the gzip is enabled.
//
// The default value is false.
GzipEnabled bool `mapstructure:"gzip_enabled"`
// GzipCompressionLevel is the compression level of the gzip.
//
// The default value is `gzip.DefaultCompression`.
GzipCompressionLevel int `mapstructure:"gzip_compression_level"`
// GzipMIMETypes is the MIME types that will be gzipped.
//
// The default value is ["text/plain", "text/html", "text/css",
// "application/javascript", "application/json", "application/xml",
// "image/svg+xml"].
GzipMIMETypes []string `mapstructure:"gzip_mime_types"`
// TemplateRoot is the root of the HTML templates. All the HTML
// templates inside it will be recursively parsed into the renderer.
//
// The default value is "templates".
TemplateRoot string `mapstructure:"template_root"`
// TemplateExts is the filename extensions of the HTML templates used to
// distinguish the HTML template files in the `TemplateRoot` when
// parsing them into the renderer.
//
// The default value is [".html"].
TemplateExts []string `mapstructure:"template_exts"`
// TemplateLeftDelim is the left side of the HTML template delimiter the
// renderer renders the HTML templates.
//
// The default value is "{{".
TemplateLeftDelim string `mapstructure:"template_left_delim"`
// TemplateRightDelim is the right side of the HTML template delimiter
// the renderer renders the HTML templates.
//
// The default value is "}}".
TemplateRightDelim string `mapstructure:"template_right_delim"`
// TemplateFuncMap is the HTML template function map the renderer
// renders the HTML templates.
//
// The default value contains strlen, substr and timefmt.
TemplateFuncMap template.FuncMap `mapstructure:"-"`
// CofferEnabled indicates whether the coffer is enabled.
//
// The default value is false.
CofferEnabled bool `mapstructure:"coffer_enabled"`
// CofferMaxMemoryBytes is the maximum number of bytes of the runtime
// memory the coffer will use.
//
// The default value is 33554432.
CofferMaxMemoryBytes int `mapstructure:"coffer_max_memory_bytes"`
// AssetRoot is the root of the asset files. All the asset files inside
// it will be recursively parsed into the coffer.
//
// The default value is "assets".
AssetRoot string `mapstructure:"asset_root"`
// AssetExts is the filename extensions of the asset files used to
// distinguish the asset files in the `AssetRoot` when loading them into
// the coffer.
//
// The default value is [".html", ".css", ".js", ".json", ".xml",
// ".svg", ".jpg", ".jpeg", ".png", ".gif"].
AssetExts []string `mapstructure:"asset_exts"`
// I18nEnabled indicates whether the i18n is enabled.
//
// The default value is false.
I18nEnabled bool `mapstructure:"i18n_enabled"`
// LocaleRoot is the root of the locale files. All the locale files
// inside it will be parsed into the i18n.
//
// The default value is "locales".
LocaleRoot string `mapstructure:"locale_root"`
// LocaleBase is the base of the locale files. It will be used when a
// locale file cannot be found.
//
// The default value is "en-US".
LocaleBase string `mapstructure:"locale_base"`
// ConfigFile is the path to the configuration file that will be parsed
// into the matching fields before starting the server.
//
// ".json" -> The configuration file is JSON-based.
//
// ".xml" -> The configuration file is XML-based.
//
// ".toml" -> The configuration file is TOML-based.
//
// ".yaml|.yml" -> The configuration file is YAML-based.
//
// The default value is "".
ConfigFile string `mapstructure:"-"`
// contains filtered or unexported fields
}
Air is the top-level struct of this framework.
func (*Air) BATCH ¶
BATCH registers a batch of routes for the methods and the path with the matching h in the router with the optional route-level gases.
The methods must either be nil (means all) or consists of one or more of the "GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS" and "TRACE". Invalid methods will be silently dropped.
func (*Air) CONNECT ¶
CONNECT registers a new CONNECT route for the path with the matching h in the router with the optional route-level gases.
func (*Air) DELETE ¶
DELETE registers a new DELETE route for the path with the matching h in the router with the optional route-level gases.
func (*Air) FILE ¶
FILE registers a new GET route and a new HEAD route with the path to serve a static file with the filename and the optional route-level gases.
func (*Air) FILES ¶ added in v0.5.0
FILES registers a new GET route and a new HEAD route with the path prefix to serve the static files from the root with the optional route-level gases.
func (*Air) GET ¶
GET registers a new GET route for the path with the matching h in the router with the optional route-level gases.
func (*Air) Group ¶
Group returns a new instance of the `Group` with the path prefix and the optional group-level gases.
func (*Air) HEAD ¶
HEAD registers a new HEAD route for the path with the matching h in the router with the optional route-level gases.
func (*Air) OPTIONS ¶
OPTIONS registers a new OPTIONS route for the path with the matching h in the router with the optional route-level gases.
func (*Air) PATCH ¶
PATCH registers a new PATCH route for the path with the matching h in the router with the optional route-level gases.
func (*Air) POST ¶
POST registers a new POST route for the path with the matching h in the router with the optional route-level gases.
func (*Air) PUT ¶
PUT registers a new PUT route for the path with the matching h in the router with the optional route-level gases.
type Group ¶
type Group struct {
// Air is where the current group belong.
Air *Air
// Prefix is the prefix of all the route paths of the current group.
Prefix string
// Gases is the group-level gases of the current group.
Gases []Gas
}
Group is a set of sub-routes for a specified route. It can be used for inner routes that share common gases or functionality that should be separate from the parent while still inheriting from it.
type Request ¶
type Request struct {
// Air is where the current request belong.
Air *Air
// Method is the method of the current request.
//
// See RFC 7231, section 4.3.
//
// For HTTP/1.x, it is from the request-line.
//
// For HTTP/2, it is from the ":method" pseudo-header.
Method string
// Scheme is the scheme of the current request, it is "http" or "https".
//
// See RFC 3986, section 3.1.
//
// For HTTP/1.x, it is from the request-line.
//
// For HTTP/2, it is from the ":scheme" pseudo-header.
Scheme string
// Authority is the authority of the current request. It may be of the
// form "host:port".
//
// See RFC 3986, Section 3.2.
//
// For HTTP/1.x, it is from the "Host" header.
//
// For HTTP/2, it is from the ":authority" pseudo-header.
Authority string
// Path is the path of the current request.
//
// For HTTP/1.x, it represents the request-target of the request-line.
// See RFC 7230, section 3.1.1.
//
// For HTTP/2, it represents the ":path" pseudo-header. See RFC 7540,
// section 8.1.2.3.
Path string
// Header is the header name-value pair map of the current request.
//
// See RFC 7231, section 5.
//
// It is basically the same for both of HTTP/1.x and HTTP/2. The only
// difference is that HTTP/2 requires header names to be lowercase. See
// RFC 7540, section 8.1.2.
Header http.Header
// Body is the message body of the current request.
Body io.Reader
// ContentLength records the length of the associated content. The value
// -1 indicates that the length is unknown. Values >= 0 indicate that
// the given number of bytes may be read from the `Body`.
ContentLength int64
// Context is the context that associated with the current request.
//
// It is canceled when the client's connection closes, the current
// request is canceled (with HTTP/2), or when the current
// request-response cycle is finished.
Context context.Context
// contains filtered or unexported fields
}
Request is an HTTP request.
func (*Request) ClientAddress ¶
ClientAddress returns the original network address that sent the r.
func (*Request) Cookie ¶
Cookie returns the matched `http.Cookie` for the name. It returns nil if not found.
func (*Request) HTTPRequest ¶
HTTPRequest returns the underlying `http.Request` of the r.
ATTENTION: You should never call this method unless you know what you are doing. And, be sure to call the `r#SetHTTPRequest()` when you have modified it.
func (*Request) LocalizedString ¶
LocalizedString returns localized string for the key.
It only works if the `I18nEnabled` is true.
func (*Request) Param ¶
func (r *Request) Param(name string) *RequestParam
Param returns the matched `RequestParam` for the name. It returns nil if not found.
func (*Request) Params ¶
func (r *Request) Params() []*RequestParam
Params returns all the `RequestParam` in the r.
func (*Request) RemoteAddress ¶
RemoteAddress returns the last network address that sent the r.
func (*Request) SetHTTPRequest ¶
SetHTTPRequest sets the hr to the underlying `http.Request` of the r.
ATTENTION: You should never call this method unless you know what you are doing.
type RequestParam ¶
type RequestParam struct {
// Name is the name of the current request param.
Name string
// Values is the values of the current request param.
//
// Access order: route param value (always at the first) > request query
// value(s) > request form value(s) > request multipart form value(s) >
// request multipart form file(s).
Values []*RequestParamValue
}
RequestParam is an HTTP request param.
func (*RequestParam) Value ¶
func (rp *RequestParam) Value() *RequestParamValue
Value returns the first value of the rp. It returns nil if the rp is nil or there are no values.
type RequestParamValue ¶
type RequestParamValue struct {
// contains filtered or unexported fields
}
RequestParamValue is an HTTP request param value.
It may represent a route param value, a request query value, a request form value, a request multipart form value or a request multipart form file value.
func (*RequestParamValue) Bool ¶
func (rpv *RequestParamValue) Bool() (bool, error)
Bool returns a `bool` from the underlying value of the rpv.
func (*RequestParamValue) File ¶
func (rpv *RequestParamValue) File() (*multipart.FileHeader, error)
File returns a `multipart.FileHeader` from the underlying value of the rpv.
func (*RequestParamValue) Float32 ¶
func (rpv *RequestParamValue) Float32() (float32, error)
Float32 returns a `float32` from the underlying value of the rpv.
func (*RequestParamValue) Float64 ¶
func (rpv *RequestParamValue) Float64() (float64, error)
Float64 returns a `float64` from the underlying value of the rpv.
func (*RequestParamValue) Int ¶
func (rpv *RequestParamValue) Int() (int, error)
Int returns an `int` from the underlying value of the rpv.
func (*RequestParamValue) Int8 ¶
func (rpv *RequestParamValue) Int8() (int8, error)
Int8 returns an `int8` from the underlying value of the rpv.
func (*RequestParamValue) Int16 ¶
func (rpv *RequestParamValue) Int16() (int16, error)
Int16 returns an `int16` from the underlying value of the rpv.
func (*RequestParamValue) Int32 ¶
func (rpv *RequestParamValue) Int32() (int32, error)
Int32 returns an `int32` from the underlying value of the rpv.
func (*RequestParamValue) Int64 ¶
func (rpv *RequestParamValue) Int64() (int64, error)
Int64 returns an `int64` from the underlying value of the rpv.
func (*RequestParamValue) String ¶
func (rpv *RequestParamValue) String() string
String returns a `string` from the underlying value of the rpv.
func (*RequestParamValue) Uint ¶
func (rpv *RequestParamValue) Uint() (uint, error)
Uint returns an `uint` from the underlying value of the rpv.
func (*RequestParamValue) Uint8 ¶
func (rpv *RequestParamValue) Uint8() (uint8, error)
Uint8 returns an `uint8` from the underlying value of the rpv.
func (*RequestParamValue) Uint16 ¶
func (rpv *RequestParamValue) Uint16() (uint16, error)
Uint16 returns an `uint16` from the underlying value of the rpv.
func (*RequestParamValue) Uint32 ¶
func (rpv *RequestParamValue) Uint32() (uint32, error)
Uint32 returns an `uint32` from the underlying value of the rpv.
func (*RequestParamValue) Uint64 ¶
func (rpv *RequestParamValue) Uint64() (uint64, error)
Uint64 returns an `uint64` from the underlying value of the rpv.
type Response ¶
type Response struct {
// Air is where the current response belong.
Air *Air
// Status is the status code giving the result of the attempt to
// understand and satisfy the request.
//
// See RFC 7231, section 6.
//
// For HTTP/1.x, it will be put in the response-line.
//
// For HTTP/2, it will be the ":status" pseudo-header.
Status int
// Header is the header name-value pair map of the current response.
//
// See RFC 7231, section 7.
//
// It is basically the same for both of HTTP/1.x and HTTP/2. The only
// difference is that HTTP/2 requires header names to be lowercase. See
// RFC 7540, section 8.1.2.
Header http.Header
// Body is the message body of the current response. It can be used to
// write a streaming response.
Body io.Writer
// ContentLength records the length of the associated content. The value
// -1 indicates that the length is unknown. Values >= 0 indicate that
// the given number of bytes has been written to the `Body`.
ContentLength int64
// Written indicates whether the current response has been written.
Written bool
// Minified indicates whether the message body of the current response
// has been minifed.
Minified bool
// Gzipped indicates whether the message body of the current response
// has been gzipped.
Gzipped bool
// contains filtered or unexported fields
}
Response is an HTTP response.
func (*Response) Defer ¶
func (r *Response) Defer(f func())
Defer pushes the f onto the stack of functions that will be called after responding. Nil functions will be silently dropped.
func (*Response) HTTPResponseWriter ¶
func (r *Response) HTTPResponseWriter() http.ResponseWriter
HTTPResponseWriter returns the underlying `http.ResponseWriter` of the r.
ATTENTION: You should never call this method unless you know what you are doing. And, be sure to call the `r#SetHTTPResponseWriter()` when you have modified it.
func (*Response) ProxyPass ¶
ProxyPass passes the request to the target and responds to the client by using the reverse proxy technique.
The target must be based on the HTTP protocol (such as HTTP(S), WebSocket and gRPC). So, the scheme of the target must be "http", "https", "ws", "wss", "grpc" or "grpcs".
func (*Response) Push ¶
func (r *Response) Push(target string, pos *http.PushOptions) error
Push initiates an HTTP/2 server push. This constructs a synthetic request using the target and the pos, serializes that request into a PUSH_PROMISE frame, then dispatches that request using the server's request handler. If pos is nil, default options are used.
The target must either be an absolute path (like "/path") or an absolute URL that contains a valid authority and the same scheme as the parent request. If the target is a path, it will inherit the scheme and authority of the parent request.
It returns `http.ErrNotSupported` if the client has disabled push or if push is not supported on the underlying connection.
func (*Response) Render ¶
Render renders one or more HTML templates with the m and responds to the client with the "text/html" content. The results rendered by the former can be inherited by accessing the `m["InheritedHTML"]`.
func (*Response) SetCookie ¶
SetCookie sets the c to the `r#Header`. Invalid cookies will be silently dropped.
func (*Response) SetHTTPResponseWriter ¶
func (r *Response) SetHTTPResponseWriter(hrw http.ResponseWriter)
SetHTTPResponseWriter sets the hrw to the underlying `http.ResponseWriter` of the r.
ATTENTION: You should never call this method unless you know what you are doing.
func (*Response) Write ¶
func (r *Response) Write(content io.ReadSeeker) error
Write responds to the client with the content.
func (*Response) WriteFile ¶
WriteFile responds to the client with a file content with the filename.
func (*Response) WriteJSON ¶
WriteJSON responds to the client with the "application/json" content v.
func (*Response) WriteMsgpack ¶
WriteMsgpack responds to the client with the "application/msgpack" content v.
func (*Response) WriteProtobuf ¶
WriteProtobuf responds to the client with the "application/protobuf" content v.
func (*Response) WriteString ¶
WriteString responds to the client with the "text/plain" content s.
func (*Response) WriteTOML ¶
WriteTOML responds to the client with the "application/toml" content v.
type WebSocket ¶
type WebSocket struct {
// TextHandler is the handler that handles the incoming text messages of
// the current WebSocket.
TextHandler func(text string) error
// BinaryHandler is the handler that handles the incoming binary
// messages of the current WebSocket.
BinaryHandler func(b []byte) error
// ConnectionCloseHandler is the handler that handles the incoming
// connection close messages of the current WebSocket.
ConnectionCloseHandler func(status int, reason string) error
// PingHandler is the handler that handles the incoming ping messages of
// the current WebSocket.
PingHandler func(appData string) error
// PongHandler is the handler that handles the incoming pong messages of
// the current WebSocket.
PongHandler func(appData string) error
// ErrorHandler is the handler that handles error occurs in the incoming
// messages of the current WebSocket.
ErrorHandler func(err error)
// Closed indicates whether the current WebSocket has been closed.
Closed bool
// contains filtered or unexported fields
}
WebSocket is a WebSocket peer.
func (*WebSocket) Listen ¶
func (ws *WebSocket) Listen()
Listen listens for the messages sent from the remote peer of the ws. After one call to it, subsequent calls have no effect.
func (*WebSocket) WriteBinary ¶
WriteBinary writes the b to the remote peer of the ws.
func (*WebSocket) WriteConnectionClose ¶
WriteConnectionClose writes a connection close to the remote peer of the ws with the status and the reason.
func (*WebSocket) WritePing ¶
WritePing writes a ping to the remote peer of the ws with the appData.